/ Published in: JavaScript
*Requires JavaScript 1.8*
fn.call and fn.apply are alternative methods to access function.call and function.apply and I don't see fn.call and fn.apply having any use but I made them for the heck of it.
Syntax:
`fn.call(function, [thisObject, [argument1, ..., argumentN]])` is equivalent to `function.call(thisObject, argument1, ..., argumentN)`
`fn.apply(function, [thisObject, [argumentsArray]])` is equivalent to `function.apply(thisObject, argumentsArray)`
Examples:
function foo(a, b) (this*a)-b;
fn.call(foo, 5, 6, 7) == 23
foo.call(5, 6, 7) == 23
fn.apply(foo, 5, [6, 7]) == 23
foo.apply(5, [6, 7]) == 23
fn.call and fn.apply are alternative methods to access function.call and function.apply and I don't see fn.call and fn.apply having any use but I made them for the heck of it.
Syntax:
`fn.call(function, [thisObject, [argument1, ..., argumentN]])` is equivalent to `function.call(thisObject, argument1, ..., argumentN)`
`fn.apply(function, [thisObject, [argumentsArray]])` is equivalent to `function.apply(thisObject, argumentsArray)`
Examples:
function foo(a, b) (this*a)-b;
fn.call(foo, 5, 6, 7) == 23
foo.call(5, 6, 7) == 23
fn.apply(foo, 5, [6, 7]) == 23
foo.apply(5, [6, 7]) == 23
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
if (typeof fn == "undefined" ) var fn = {}; fn.call = function call(fn /*, [thisp, [arg1, ..., argN]]*/) Function.prototype.call.apply(fn, Array.prototype.slice.call(arguments).splice(1)); fn.apply = function apply(fn, thisp, args) { if ( args ) args.splice(0, 0, thisp); return Function.prototype.call.apply(fn, args) };