Object of a callee

Discussion in 'Javascript' started by tylersimon@gmail.com, Oct 6, 2007.

  1. Guest

    Hi,

    I am trying to write some javascript in which a method in a custom
    object calls a global function. Within this global function I wish to
    establish what the object was that called me. I can use the "callee"
    method on the function to get the function that was called but I do
    not seem to be able to get the object.

    Is there a way to do this?

    Simon
     
    , Oct 6, 2007
    #1
    1. Advertising

  2. RobG Guest

    On Oct 6, 11:02 pm, wrote:
    > Hi,
    >
    > I am trying to write some javascript in which a method in a custom
    > object calls a global function. Within this global function I wish to
    > establish what the object was that called me. I can use the "callee"
    > method on the function to get the function that was called but I do
    > not seem to be able to get the object.
    >
    > Is there a way to do this?


    callee.caller


    --
    Rob
     
    RobG, Oct 6, 2007
    #2
    1. Advertising

  3. RobG wrote:
    > On Oct 6, 11:02 pm, wrote:
    >> I am trying to write some javascript in which a method in a custom
    >> object calls a global function. Within this global function I wish to
    >> establish what the object was that called me. I can use the "callee"
    >> method on the function to get the function that was called


    `callee' is a standardized *non-function property* of the object referred
    to by `arguments'. Its use as a property of Function objects would be
    proprietary, and therefore unwise; it is not supported in JavaScript 1.5
    this way. Its use as a property of the `arguments' property of Function
    objects is proprietary and deprecated.

    >> but I do not seem to be able to get the object.
    >>
    >> Is there a way to do this?

    >
    > callee.caller


    `caller' is a proprietary property of both Function objects and the object
    referred to by `arguments'; its use in either way is deprecated since
    JavaScript 1.3.

    But more important, it does not yield a reference to the object that called
    the function (which the OP was actually looking for), but to the Function
    object that created the local context from which the function was called.

    Therefore, the calling method of the user-defined object should pass its
    `this' reference to the global function instead:

    function myGlobal(caller)
    {
    // ...
    }

    ({foo: function() { myGlobal(this); }}).foo();

    The alternative is that the global function is called as a method of the
    user-defined object, and that the `this' value is used there:

    var _global = this;

    function myGlobal()
    {
    if (this != _global)
    {
    // not called by the Global Object
    }
    }

    ({foo: function() { myGlobal.call(this); }}).foo();
    or
    ({foo: function() { myGlobal.apply(this); }}).foo();

    It should be noted that global functions are methods of the Global Object.


    PointedEars
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
     
    Thomas 'PointedEars' Lahn, Oct 6, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jai hanuman

    caller / callee graph ...

    jai hanuman, Dec 16, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    667
    jai hanuman
    Dec 16, 2003
  2. John Dalberg
    Replies:
    0
    Views:
    733
    John Dalberg
    Jun 21, 2004
  3. Daryl Davis

    Invalid Callee

    Daryl Davis, Jul 2, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,495
    Daryl Davis
    Jul 2, 2004
  4. Jerald Fijerald

    longjmp to the callee

    Jerald Fijerald, Feb 24, 2005, in forum: C Programming
    Replies:
    2
    Views:
    344
    Eric Sosman
    Feb 24, 2005
  5. Replies:
    19
    Views:
    453
    Ben Bacarisse
    Feb 22, 2006
Loading...

Share This Page