473,215 Members | 1,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,215 software developers and data experts.

Caller method

I have read that the function.caller method is now depricated. I see
alot of browsers still support it but Opera 7 does not. Is there a way
to get the name of the caller of a function in Opera 7?

Jul 23 '05 #1
9 4319
<ja********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I have read that the function.caller method is now depricated. I see
alot of browsers still support it but Opera 7 does not. Is there a way to get the name of the caller of a function in Opera 7?


No, because a function doesn't have a single "name".

function target() {
}
function a() {
target();
}
b = c = d = a;
c();
// who called target()? -c- did, but so did -a- and -b-
// because they all reference the same function

Besides, I'm not sure you can obtain the "name" of the function from
arguments.caller anyway. What arguments.caller was was a -reference- to
the calling function, not it's name.

arguments.caller was deprecated because it is not needed, there are
almost certainly other ways of doing what you are attempting to do.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #2
> I have read that the function.caller method is now depricated. I see
alot of browsers still support it but Opera 7 does not. Is there a way
to get the name of the caller of a function in Opera 7?


Please tell us why you think you need a deprecated feature. Perhaps
there is a better way to accomplish your task.

http://www.crockford.com/javascript/survey.html
Jul 23 '05 #3
Grant Wagner wrote:
<ja********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I have read that the function.caller method is now depricated. I see alot of browsers still support it but Opera 7 does not. Is there a way
to get the name of the caller of a function in Opera 7?


No, because a function doesn't have a single "name".

function target() {
}
function a() {
target();
}
b = c = d = a;
c();
// who called target()? -c- did, but so did -a- and -b-
// because they all reference the same function


Even if there were only a single reference to the function, it wouldn't
be possible to "reverse engineer" the name of the variable containing
the reference. However, I don't thing that's what the OP was asking
for.
Besides, I'm not sure you can obtain the "name" of the function from
arguments.caller anyway. What arguments.caller was was a -reference- to the calling function, not it's name.

Correct. But a reference to a function, in particular one provided by
arguments.caller, can be used to obtain the string representation of
the invoking function, which in turn will contain it's name. A robust
RegExp then applied to the string could reliably return the name of the
function that was used to invoke the current function (noting that i)
arguments.caller is null when the invocation occurs from the global
environment, and that ii) the invoker could be nameless, i.e.,
anonymous).
arguments.caller was deprecated because it is not needed, there are
almost certainly other ways of doing what you are attempting to do.


Agreed. My comments fall into the quibble category -- they don't
constitute a recommendation to the OP.

Regards,

../rh

Jul 23 '05 #4
Well I tell you what I need to accomplish and perhaps there is a way of
doing so.

function a(){

}

function b(){
a()
....
more code
....
}

Function a needs the code which called function a or the name of the
function. In this case function a would need to retrieve the code of
function b or the name "b". In IE the function.caller will give me:
function b(){
a()
....
more code
....
}

which then I can parse and retrieve all the function code or if I
wanted the function name. Mozilla, IE, Netscape all can be used but I
can't figure out a work around for Opera. Is there a way? Thanks

co********@yahoo.ca wrote:
Grant Wagner wrote:
<ja********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I have read that the function.caller method is now depricated. I see alot of browsers still support it but Opera 7 does not. Is there
a way
to get the name of the caller of a function in Opera 7?
No, because a function doesn't have a single "name".

function target() {
}
function a() {
target();
}
b = c = d = a;
c();
// who called target()? -c- did, but so did -a- and -b-
// because they all reference the same function


Even if there were only a single reference to the function, it

wouldn't be possible to "reverse engineer" the name of the variable containing
the reference. However, I don't thing that's what the OP was asking
for.
Besides, I'm not sure you can obtain the "name" of the function from arguments.caller anyway. What arguments.caller was was a
-reference- to
the calling function, not it's name.

Correct. But a reference to a function, in particular one provided by
arguments.caller, can be used to obtain the string representation of
the invoking function, which in turn will contain it's name. A

robust RegExp then applied to the string could reliably return the name of the function that was used to invoke the current function (noting that i)
arguments.caller is null when the invocation occurs from the global
environment, and that ii) the invoker could be nameless, i.e.,
anonymous).
arguments.caller was deprecated because it is not needed, there are
almost certainly other ways of doing what you are attempting to do.


Agreed. My comments fall into the quibble category -- they don't
constitute a recommendation to the OP.

Regards,

../rh


Jul 23 '05 #5
> Well I tell you what I need to accomplish and perhaps there is a way of
doing so.

function a(){

}

function b(){
a()
...
more code
...
}

Function a needs the code which called function a or the name of the
function. In this case function a would need to retrieve the code of
function b or the name "b". In IE the function.caller will give me:
function b(){
a()
...
more code
...
}

which then I can parse and retrieve all the function code or if I
wanted the function name. Mozilla, IE, Netscape all can be used but I
can't figure out a work around for Opera. Is there a way? Thanks


Why would you want to do that?

The correct way for b to inform a is to pass the information as a
parameter. Why do you feel you have to do this incorrectly?

http://www.crockford.com/javascript/survey.html
Jul 23 '05 #6

Douglas Crockford wrote:
Well I tell you what I need to accomplish and perhaps there is a way of doing so.

function a(){

}

function b(){
a()
...
more code
...
}

Function a needs the code which called function a or the name of the function. In this case function a would need to retrieve the code of function b or the name "b". In IE the function.caller will give me: function b(){
a()
...
more code
...
}

which then I can parse and retrieve all the function code or if I
wanted the function name. Mozilla, IE, Netscape all can be used but I can't figure out a work around for Opera. Is there a way? Thanks


Why would you want to do that?

The correct way for b to inform a is to pass the information as a
parameter. Why do you feel you have to do this incorrectly?

http://www.crockford.com/javascript/survey.html

I am not doing anything incorrectly. Yes b could pass a itself as a
parameter. Many browsers support the funciton.caller method so you
would not have to, which in my instance is not favorable to do for
other reasons which are too lengthy to get into. So please assume that
the behavior I need is set in stone. Function b needs to know the
function name or the function code which has called it. Opera is the
only other browser I would like it to work in. Anybody have any ideas
for an Opera workaround?

Jul 23 '05 #7
> I am not doing anything incorrectly. Yes b could pass a itself as a
parameter. Many browsers support the funciton.caller method so you
would not have to, which in my instance is not favorable to do for
other reasons which are too lengthy to get into. So please assume that
the behavior I need is set in stone. Function b needs to know the
function name or the function code which has called it. Opera is the
only other browser I would like it to work in. Anybody have any ideas
for an Opera workaround?


funciton.caller, as you say, is not standard. You still haven't
explained why you need to use a non-standard feature. If you did this in
a standard way, you would not need a workaround. If your reasons are too
lengthy to get into, then I suspect that they are not very good reasons.

If you told us what you are trying to accomplish, we might be able to
suggest a better way to approach it.

http://www.crockford.com/#javascript
Jul 23 '05 #8
Douglas,
As I explained in the above post I am trying to accomplish getting
the function name or code of the function which has called the
function. That is what I am trying to accomplish. If you are asking why
I need the function name or code I need it in order to call the super
classes overloaded method. I am aware that I can pass that as a
variable, infact it works for every browser if I pass it as an
argument. I would like to not have to pass that as a variable (Opera
currently is the only browser which I need to support that has an
issue). So I was wondering if there was a work around for opera to get
the function caller's name without passing it as an argument. If you do
not know a work around for this please just say so. Any body have a
proposed work around?

Douglas Crockford wrote:
I am not doing anything incorrectly. Yes b could pass a itself as a
parameter. Many browsers support the funciton.caller method so you
would not have to, which in my instance is not favorable to do for
other reasons which are too lengthy to get into. So please assume that the behavior I need is set in stone. Function b needs to know the
function name or the function code which has called it. Opera is the only other browser I would like it to work in. Anybody have any ideas for an Opera workaround?
funciton.caller, as you say, is not standard. You still haven't
explained why you need to use a non-standard feature. If you did this

in a standard way, you would not need a workaround. If your reasons are too lengthy to get into, then I suspect that they are not very good reasons.
If you told us what you are trying to accomplish, we might be able to suggest a better way to approach it.

http://www.crockford.com/#javascript


Jul 23 '05 #9
> As I explained in the above post I am trying to accomplish getting
the function name or code of the function which has called the
function. That is what I am trying to accomplish. If you are asking why
I need the function name or code I need it in order to call the super
classes overloaded method. I am aware that I can pass that as a
variable, infact it works for every browser if I pass it as an
argument. I would like to not have to pass that as a variable (Opera
currently is the only browser which I need to support that has an
issue). So I was wondering if there was a work around for opera to get
the function caller's name without passing it as an argument. If you do
not know a work around for this please just say so. Any body have a
proposed work around?


Have you looked at http://www.crockford.com/javascript/inheritance.html ?
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Koen Van Herck | last post by:
For debugging/logging purposes, I have a function def Log(msg): print '%s.%s: %s' % (cls, method, msg) I call this function from a class method, and I would like to retrieve the name of the...
2
by: David Abrahams | last post by:
Is there any way to determine the file and line number (if any) of a method's invocation from within its body? Many Thanks in advance, Dave -- David Abrahams Boost Consulting...
8
by: John Smith | last post by:
Hi, I'm writing a library in C++ which is supposed to be used by people using C. One function I have must return a string to users which is arbitrary length. The user must be able to use this...
5
by: oliver | last post by:
Hi, the structure of my source code is like this: <script> C = function(){ //some initialization } C.prototype.start = function{ //some action
20
by: 2pac | last post by:
in this scenario foo1 ---calls---> foo2 is it possible for me to print out - when the control is within foo2 - the caller of foo2 the information is obviously there in the stack - am wondering...
2
by: Fabio Cannizzo | last post by:
Is it possible to know who is the caller of some running method? In ogther words, given a method of some class which is running, is there a way, inside the method, to find out from which namespace...
14
by: Genival | last post by:
Hello all... First sorry my bad English. Look next code Dim oDS as Dataset ' <= Caller oDs = MyFunc 'other caller type Dim i as integer = MyFunc
5
by: pamelafluente | last post by:
Hi guys, How do I get the full name of the current (overload) function or sub (whatever it be) ? Sub SomeFunction() Dim FullNameOfThisFunction = ??? msgbox(FullNameOfThisFunction )
7
by: =?UTF-8?B?QW50w7NuaW8gTWFycXVlcw==?= | last post by:
Hi, Sorry if this's been discussed before, I couldn't find it. As well you know, the ECMAScript standard doesn't include any way to access a function's caller. This has been available on Mozilla...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.