Callee scope

Hi,
I’m following
peter.michaux.ca - The window.onload Problem (Still)


function init() {
    // quit if this function has already been called
    if (arguments.callee.done) return;

    // flag this function so we don't do the same thing twice
    arguments.callee.done = true;

};


I mean argumentes.callee is a reference to the function being called
so what arguments.callee.done is ? Is it a local var ?

Can you explain me , please ?

You are best off avoiding arguments.callee completely.

It was deprecated in JavaScript 1.4 and has never been a part of any ECMAscript standard.

With regard to arguments.callee.done - since arguments.callee is a reference to the function that contains it (to allow recursive calls in anonymous functions) with your particular example arguments.callee.done is a reference to init.done - it isn’t quite the same as a local variable as there would be separate local variables for each recursion of the init function whereas done has only one copy shared by all the calls to init.

:slight_smile:

function init() {
    // quit if this function has already been called
    if (init.done) return;
 
    // flag this function so we don't do the same thing twice
   init.done = true;
 
}