473,399 Members | 2,774 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,399 software developers and data experts.

Get the name of the caller object as string?

Hi,

is there a way to get the name of the calling object of a method?

function MyFunction()
{
this.SayCallersName = _SayCallersName;
}

function _SayCallersName()
{
alert("how to get 'oTest' as output here?");
}

var oTest = new MyFunction();
oTest.SayCallersName();

What I want as an output is the name of the object I have created
without passing it to the constructor.
So I do not want oTest = new MyFunction("oTest") or something like
that.
Is this possible in JScript?

Just curious...please do not start a thread about "why are you doing it
that way?" - It's for testing purposes...just playing around with the
JScript language and trying out weird stuff. :-)

René

Oct 19 '06 #1
1 2982

re**********@online.de wrote:
Hi,

is there a way to get the name of the calling object of a method?

function MyFunction()
{
this.SayCallersName = _SayCallersName;
}

function _SayCallersName()
{
alert("how to get 'oTest' as output here?");
}

var oTest = new MyFunction();
oTest.SayCallersName();

What I want as an output is the name of the object I have created
without passing it to the constructor.
So I do not want oTest = new MyFunction("oTest") or something like
that.
Is this possible in JScript?

Just curious...please do not start a thread about "why are you doing it
that way?" - It's for testing purposes...just playing around with the
JScript language and trying out weird stuff. :-)

René
Hi

I think this has cropped up a few times before.

If I recall correctly, the answer is no.

Consider the practicalities, if multiple variables contain a reference
to the same object:-

var oTest = new MyFunction();

var oAnotherName = oTest;

.....now which name would you want the language to give you?

Regards
Julian

Oct 19 '06 #2

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

Similar topics

17
by: warteschlange | last post by:
is there a way to find out the object/function name from inside object/function. function coffee(){ alert(this.someHowGetMyNameFuncOrVar); => should give me 'coffee' } var milk = new...
4
by: Hmnt | last post by:
Hi Hope ur smart enough to get what i wanna ask ... (from the sub line Brief Explaination I've 2 classas Class1 and Class Now i've an instance of Class2 ( Class2 objC2 = new Class2(); Next i...
1
by: jg | last post by:
I have searched marshaling articles from MSDN and Google but I am stuck with solving my problem to marshal arrays to COM caller from my managed COM class I built a .net COM class in VB and...
9
by: Csaba Gabor | last post by:
Inside a function, I'd like to know the call stack. By this I mean that I'd like to know the function that called this one, that one's caller and so on. So I thought to do: <script...
3
by: Rico | last post by:
Hello, I have a generic process that logs errors from different sources. When I call this code, I'd like to also submit the name of the function or sub that is raising the error without having...
45
by: Zytan | last post by:
Shot in the dark, since I know C# doesn't have macros, and thus can't have a stringizer operator, but I know that you can get the name of enums as strings, so maybe you can do the same with an...
20
by: Andrew Morton | last post by:
Is it possible to have two function declarations which take the same parameters but return different types depending on how the function is used? function f(x) as string ' return a string end...
7
by: jackchang1 | last post by:
It's not difficult getting the function name of the caller but if the caller is an object's method, how do you get the method name? <html> <head> <script type="text/javascript"> function...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.