Strange JavaScript Question

M

Mike McCollister

I am trying to do what is most likely impossible. In JavaScript I want to
know the variable name that a new object is assigned to from within the
object. For example, if I do this

var testObject = new TestObject();

then the TestObject object will, with some magic function, get the
assignment variable name which in the above case is "testObject". I'm
thinking that the caller or callee property might be of use.

function TestObject()
{
// constructor
{
// constructor stuff here
var html = "";

var assignmentName = SomeMagicFunction(); // ??? where's the magic

html += "<img onClick='" + assignmentName + ".DoThisFunction()'>";

document.writeln(html);
}
}

If this is impossible, I'll just pass the assignee name as a parameter to
the object. Just wanting to make the object as smart as possible.

Thanks,

Mike
 

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

Top