When testing for a partial evaluation function:
function partialEval(fn)
{
var sliceMethod = Array.prototype.slice;
if(arguments.length > 1)
{
var aps = sliceMethod.call(arguments, 1);
}
return function () {
return fn.apply(this,aps.concat( sliceMethod.call(arguments) ));
};
}
var x= function add(a,b,c,d){
console.debug(a + " - " + b + " - " + c + " - " + d);
return a+b+c+d;
}
var pa = partialEval(add, 1,2); // Query here
var zz = pa(3,4);
console.debug(zz);
What is the difference between calling partialEval(add,1,2) and partialEval (x,1,2)?
I understand that x is a function literal here and using x gives the correct results. But when I use add as a function name sent to the partialEval method the output is coming as 3. Can someone explain the execution differences between the two?
thanks.
When you do:
addshould only exist inside the function (and refer to itself). Outside of the function you need to usex,addwill beundefined.