Skip to content

Instantly share code, notes, and snippets.

@lyuehh
Created October 28, 2012 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lyuehh/3968365 to your computer and use it in GitHub Desktop.
Save lyuehh/3968365 to your computer and use it in GitHub Desktop.
Function.prototype.bind
Function.prototype.bind_a = function() {
var method = this,
slice = Array.prototype.slice,
args = slice.apply(arguments),
obj = args.shift();
return function() {
var arg = slice.apply(arguments);
return method.apply(obj,args.concat(arg));
};
};
var x = function(a,b) {
return this.value + a + b;
};
var y = x.bind_a({value: 123},'111');
console.log(y('a'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment