No, actually, I'm really not guessing. He is saying very plainly and
unambiguously what it is that he wants; we're just having trouble
understanding it because anyone with the slightest knowledge of
programming -- in any language -- knows that what he's asking for is
complete nonsense...
This is the last reply I'm going to post because it seems that it
can't be done in Javascript, but I just had to reply to this that just
because you apparently don't know a lot about programming is no reason
to project your inadequacy on others.
As most people who *actually* have knowledge about programming know,
almost every language maintains something called a "symbol table" that
associates names of things with what and where they are. When you say
something like:
var foo = 12;
the symbol table is what associates the memory location that holds the
value of 12 with the name "foo." Later, if you say:
foo += 4;
Javascript uses the symbol table to know what exactly is supposed to
be incremented by four. I know, this is all pretty sophisticated and
might seem to work like "magic" as far as you can tell. But I assure
you, it's *not* magic, it's *not* nonsense, and it usually works
pretty well behind the scenes with no need to worry much about it.
However, there might be an occasion--for example, if one were working
on a debugging function--when it would be handy to have limited access
to the symbol table, preferably through some mechanism built into the
language itself instead of through a separate debugging program or
creating fields to manually store instance names. That way, if some
function fails on one of a thousand or so object instances within a
program, the debugging function could say something like, "Hey, the
foo object is the one that's hosed up" at runtime, making
troubleshooting the problem much easier.
Maybe you've never worked with a debugger that has access to programs'
symbol tables and that can show you this information. I have, but not
in Javascript, though I'm certain they exist. Maybe you've never
heard of a stack trace, or think that it really does work by magic
when it looks like it's pulling the names of calling functions out of
thin air. I assure you, though, that such concepts aren't nonsense,
they're extremely practical and used quite frequently by *real*
programmers.
All I needed to know is if there's a way to get this information at
runtime, which from what I've read here, there's not. That's all,
question answered, no need to be condescending.
I apologize if my attempt at simplification was confusing. I figured
that if Javascript did have some mechanism to access the name(s) of
objects within those objects, it would probably be something
relatively obvious to someone who's worked with the language for a
while, and talking about symbol tables and stack traces would have
been overkill and would have been more confusing, not less.
I sincerely hope that next time you don't know something, you actually
try learning a few things when you're out of your league instead of
treating people who are likely smarter and more experienced than you
like they're stupid.
To the others who have posted in this thread, thanks for the input.
I'll probably just go with VK's original suggestion of manually
telling new objects what name I've given them.