473,323 Members | 1,560 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,323 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 4328
<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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.