Purpose Of Variable
Solution 1:
The tutorial is showing that removing references to objects does not delete the object itself.
ninja
which contained a function yell
is shown to have the reference to that function removed, while the reference still exists in a different variable, samurai
. Calling the function through samurai
even though ninja
no longer has it shows that objects persist past the variable referencing them no longer doing so.
Solution 2:
It's to demonstrate that even though the ninja
object is no longer referenced, you can still call it and the recursion will work.
Of course, there's two major problems I have with that tutorial.
You can use
arguments.callee
to call the current function, instead of having to name the function itself. Especially useful for anonymous functions. Deprecated in strict mode, but ask me if I give a rat's arse.You don't need recursion for this function anyway:
return "hiy"+newArray(n+1).join("a");
Solution 3:
If you notice the previous code: http://ejohn.org/apps/learn/#13
It shows that anonymous functions disappear once the parent object has been cleared.
#14 shows that if you give the anonymous function a name, it would still be able to reference it if set to another variable.
Post a Comment for "Purpose Of Variable"