Last active
February 22, 2017 12:54
-
-
Save npras/23d6ade876344174225b1b5f8abc39a7 to your computer and use it in GitHub Desktop.
Gist explaining method binding to outer scope
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
let myLib = (function(){ | |
this.libName = 'in lib'; | |
let obj = { | |
libName: 'in obj', | |
toCaps() { | |
return this.libName.toUpperCase(); | |
} | |
}; | |
console.log(obj.toCaps()); // IN OBJ (bound to the object) | |
boundToCaps = obj.toCaps.bind(this); | |
console.log(boundToCaps()); // IN LIB (bound to the myLib scope) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment