Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Object of a callee

Reply
Thread Tools

Object of a callee

 
 
tylersimon@gmail.com
Guest
Posts: n/a
 
      10-06-2007

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

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      10-06-2007
On Oct 6, 11:02 pm, (E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      10-06-2007
RobG wrote:
> On Oct 6, 11:02 pm, (E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Echo at the "callee" phone pike_by_nature@hotmail.com UK VOIP 6 01-10-2006 06:19 PM
longjmp to the callee Jerald Fijerald C Programming 2 02-24-2005 10:13 PM
Invalid Callee Daryl Davis ASP .Net 0 07-02-2004 05:26 PM
Best way to bubble up error message from callee to caller? John Dalberg ASP .Net 0 06-21-2004 04:51 PM
caller / callee graph ... jai hanuman ASP .Net 0 12-16-2003 03:34 PM



Advertisments