Skip to content

Instantly share code, notes, and snippets.

@qcom
Last active January 2, 2016 08:49
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save qcom/8279082 to your computer and use it in GitHub Desktop.
Function.prototype.bind = function(thisObj) {
var that = this;
return function() {
return that.apply(thisObj, arguments);
};
};
function fn() {
return this;
}
var a = { a : 1 }; // { a : 1 }
var b = { b : 2 }; // { b : 2 }
console.log(fn.call(a));
console.log(fn.call(b));
var boundFn = fn.bind(a);
console.log(boundFn()); // { a : 1 }
console.log(boundFn.call(b)); // { a : 1 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment