Skip to content

Instantly share code, notes, and snippets.

@lsitters
Last active August 26, 2016 15:13
Show Gist options
  • Save lsitters/561ff43d0f02be8ccf484acc6d41b6bf to your computer and use it in GitHub Desktop.
Save lsitters/561ff43d0f02be8ccf484acc6d41b6bf to your computer and use it in GitHub Desktop.
Bind.js
function foo(something){
console.log( this.a, something );
return this.a + something;
}
function bind(fn, obj) {
return function() {
return fn.apply(obj, arguments);
};
}
var obj = {
a: 1;
}
var bar = bind(foo, obj); // write this bind function.
var baz = bar(3); // 1 3
console.log(baz); // 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment