Assuming:
var x = {
y: function(n){
console.log(n);
console.log(n+":"+( n > 0 ? arguments.callee(n-1) + "o" : "all" ));
}
};
x.y(4)
Console log:
4
3
2
1
0
0 -> all
1 -> o
2 -> o
3 -> o
4 -> o
The first part of the console.log makes sense to me, we're starting with n=4 , and calling the function itself with n-1, ends up 4,3,2,1,0.
However, the output of
console.log(n+":"+( n > 0 ? arguments.callee(n-1) + "o" : "all" ));
is a bit irritating since it returns the result in a 'reversed' order. Why is the value of n as first part of that execution, without arguments.callee in it giving a different result than calling it from within a ternary operator with arguments.callee? Is this a matter of pure definition or is there another logic reason for this?
The process would be as the following:
(n=4) = ( 4 > 0 ? arguments.callee(3) + "o" : "all" ) = "o"
(n=3) = ( 3 > 0 ? arguments.callee(2) + "o" : "all" ) = "o"
(n=2) = ( 2 > 0 ? arguments.callee(1) + "o" : "all" ) = "o"
(n=1) = ( 1 > 0 ? arguments.callee(1) + "o" : "all" ) = "o"
(n=0) = ( 0 > 0 ? arguments.callee(1) + "o" : "all" ) = "all"
Doesn't this have to end up in ooooall instead of alloooo?
Cheers