SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: callee scope

  1. #1
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    callee scope

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



    Code JavaScript:
    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 ?

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    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;
     
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •