Skip to content

Instantly share code, notes, and snippets.

@Bijesse
Forked from anonymous/index.html
Created August 17, 2016 01:09
Show Gist options
  • Save Bijesse/522bcca2bd6c336c8577bd9d44866fc9 to your computer and use it in GitHub Desktop.
Save Bijesse/522bcca2bd6c336c8577bd9d44866fc9 to your computer and use it in GitHub Desktop.
.call with this // source http://jsbin.com/fofawef
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>.call with this</title>
</head>
<body>
<script id="jsbin-javascript">
function speak (prefix) {
console.log(prefix + ' ' + this.sound);
}
var dog = {
sound: 'woof'
}
var cat = {
sound: 'meow'
}
speak.call(cat, 'the dog says')
// 'the dog says woof'
</script>
<script id="jsbin-source-javascript" type="text/javascript">
function speak (prefix) {
console.log(prefix + ' ' + this.sound);
}
var dog = {
sound: 'woof'
}
var cat = {
sound: 'meow'
}
speak.call(cat, 'the dog says')
// 'the dog says woof'
</script></body>
</html>
function speak (prefix) {
console.log(prefix + ' ' + this.sound);
}
var dog = {
sound: 'woof'
}
var cat = {
sound: 'meow'
}
speak.call(cat, 'the dog says')
// 'the dog says woof'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment