To do this, you need to create your own binding function. The main reason for having .bind() was to consider the non-lexically defined this . Thus, they did not provide any way to use it without installing this .
Here is a simple example that you could use:
Function.prototype.argBind = function() { var fn = this; var args = Array.prototype.slice.call(arguments); return function() { return fn.apply(this, args.concat(Array.prototype.slice.call(arguments))); }; };
These are pretty bare bones and don't apply to a function called as a constructor, but you can add this support if you want.
You can also improve it to behave like a native .bind() , unless null or undefined is passed as the first argument.
Function.prototype.argBind = function(thisArg) { // If `null` or `undefined` are passed as the first argument, use `.bind()` if (thisArg != null) { return this.bind.apply(this, arguments); } var fn = this; var args = Array.prototype.slice.call(arguments); return function() { return fn.apply(this, args.concat(Array.prototype.slice.call(arguments))); }; };
source share