Skip to content

Instantly share code, notes, and snippets.

@npras
Last active Feb 22, 2017
Embed
What would you like to do?
Gist explaining method binding to outer scope
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