Get the name of the caller object as string?

R

rene.ruppert

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é
 
J

Julian Turner

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,186
Latest member
vinaykumar_nevatia

Latest Threads

Top