Monday, February 13, 2012

Function.apply and Function.call in JavaScript

Function.apply and Function.call in JavaScript: "We can also pass arguments to the target function via call():

var x = 10;
var o = { x: 15 };
function f(message)
{
    alert(message);
    alert(this.x);
}

f("invoking f");
f.call(o, "invoking f via call");
The apply() method is identical to call(), except apply() requires an array as the second parameter. The array represents the arguments for the target method."

'via Blog this'