yqt
9/25/2013 - 9:10 AM

use both call and apply together to create fast, unbound wrappers

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);
};