Hi everyone. Have a simple function, everything works fine, but I can’t understand how in apply method works this. Here code:
First:
var calculate = function() {
var fn = Array.prototype.pop.call( arguments );
return fn.apply( this, arguments );
}
var sum = function( x, y ) {
return ( x + y );
}
var sumResult = calculate( 2, 2, sum );
console.log( sumResult );
The same code works if I insted this, write null :
var calculate = function() {
var fn = Array.prototype.pop.call( arguments );
return fn.apply( null, arguments );
}
I know that first argument in apply is object in context, but if I write null what context there is?
Can somebody explain? Thanks.