Skip to content

Instantly share code, notes, and snippets.

@ahmed-anas
Created February 11, 2017 04:44
Show Gist options
  • Select an option

  • Save ahmed-anas/2c5d3fe08ff27ffb276d8720677ad3f5 to your computer and use it in GitHub Desktop.

Select an option

Save ahmed-anas/2c5d3fe08ff27ffb276d8720677ad3f5 to your computer and use it in GitHub Desktop.
a basic implementation of bind without various properties
let myObj = {
str: 'Original Scope',
foo: function() {
console.log(`my scope is ${this.str}.`);
}
}
function myBind(func, scope){
for(let prop in scope){
this[prop] = scope[prop];
}
this.funcToCall = func;
return this.funcToCall;
}
myObj.foo();
var newFoo = myBind(myObj.foo, {str: 'Overwridden Scope'});
newFoo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment