Skip to content

Instantly share code, notes, and snippets.

@texel
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save texel/8961342 to your computer and use it in GitHub Desktop.
Save texel/8961342 to your computer and use it in GitHub Desktop.
var wrapper = function() {
var internalVar = 1
var internalFunction = function () {
console.log("internalVar:", internalVar);
}
return internalFunction;
}
var capturedFunction = wrapper();
capturedFunction();
// 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