Last active
August 29, 2015 13:56
-
-
Save texel/8961342 to your computer and use it in GitHub Desktop.
This file contains 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
var wrapper = function() { | |
var internalVar = 1 | |
var internalFunction = function () { | |
console.log("internalVar:", internalVar); | |
} | |
return internalFunction; | |
} | |
var capturedFunction = wrapper(); | |
capturedFunction(); |
This file contains 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
// obj1 is an object with a name and a function | |
// called printName | |
var obj1 = { | |
name: 'obj1', | |
printName: function () { | |
console.log(this.name); | |
} | |
} | |
// obj2 just has a name | |
var obj2 = {name: 'obj2'} | |
// call printName | |
obj1.printName(); | |
// use "call" this time, passing in obj2 as the | |
// context argument. | |
obj1.printName.call(obj2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment