Skip to content

Instantly share code, notes, and snippets.

@yqt
Created September 25, 2013 09:10
Show Gist options
  • Save yqt/6697027 to your computer and use it in GitHub Desktop.
Save yqt/6697027 to your computer and use it in GitHub Desktop.
use both call and apply together to create fast, unbound wrappers
/*retrieved from http://bonsaiden.github.io/JavaScript-Garden/#function.arguments*/
function Foo() {}
Foo.prototype.method = function(a, b, c) {
console.log(this, a, b, c);
};
// Create an unbound version of "method"
// It takes the parameters: this, arg1, arg2...argN
Foo.method = function() {
// Result: Foo.prototype.method.call(this, arg1, arg2... argN)
Function.call.apply(Foo.prototype.method, arguments);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment