I checked @mrid and @Amadan's answers and thought for a bit, I think I understood this and came up with a simpler answer, and my explanation in my question is not entirely true.
If I uncomment the first commented line,
var ninja = {};
I assign a ninja to an empty object, and therefore I try to run "samurai.yell (4);", I get an error. The reason is that the samurai is trying to find the ninja through his "chain of visibility" (that is, some closing magic that she finds, but when she tries to find if the ninja has the yell property, it disappeared, so the error is. Although the samurai still contains a link to this anonymous function (which implies that it can still run this function), when this anonymous function tries to run ninja.yell() , it will no longer be able to find it, therefore an error.
A way to fix this, of course, use this ,
var ninja = { yell: function (n) { return n > 0 ? this.yell(n-1) + "a" : "hiy"; } }; var samurai = { yell: ninja.yell }; var ninja = {}; samurai.yell(4);
Another way is to use the function name of the function,
var ninja = { yell: function foo(n) { return n > 0 ? foo(n-1) + "a" : "hiy"; } }; var samurai = { yell: ninja.yell }; var ninja = {}; samurai.yell(4);
And everything should work.
If I uncomment the second commented line,
delete ninja;
I actually do nothing. delete is intended only to βdeleteβ the properties of an object (you can never delete anything in Javascript, garbage handlers), it returns true if the operation was successful, otherwise false. Therefore, "delete" does not work on ninja , so simply speaking, I am not doing anything extra for ninja when I uncomment "delete ninja;", it still works as usual.
Therefore, you can forget everything that I said about the "link" and "delete" in my question, they are not relevant and do not correspond to reality.