-
-
Save Bijesse/522bcca2bd6c336c8577bd9d44866fc9 to your computer and use it in GitHub Desktop.
.call with this // source http://jsbin.com/fofawef
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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