On May 6, 3:25 pm, Matthias Watermann <li...@mwat.dewrote:
The main question, however, is whether JavaScript
provides a way to let an object figure out its name. I understand
that's not the case, right?
Right - because there is not such thing as "instance name". In this
aspect Javascript is no any different from any other programming
language like say C++ or Java. There is an instance object, and a
reference to this instance can be assigned to different identifiers or
you even may keep it anonymous, say
(new childOne).aMethod();
- not to say this approach is used too often, just to help to separate
in your mind a reference identifier and the object itself.
Of course each instance has its own objectID (DispID) to distinguish
several instances of the same class, but it is an internal system
property which is not accessible from the language itself. Again, it
is not any different from other OO languages.
>
[...]
From my rather long experience which you are free to disregard of
course, the "necessity" to know the current instance reference
identifier is a strong indication that the current programming pattern
is targeted straight to hell where it will sooner or later ;-)
Well, I can't reject that, of course. In my case the object's name
is needed for sending it (along with other data) back to the web-server
which returns a piece of JavaScript code invocing an instance method
(the name and API of which is defined by contract). And since there may
be several concurrent requests (by different objects) I've to make sure
somehow that each response reaches the respective requester.
A month later I would suggest to use WebService mechanics for that,
but now I see confirmed that Firefox 3.x will not have it as a default
feature for whatever reason:
http://developer.mozilla.org/en/docs..._WSDL_Proxying
So just stick then with manually setting initial instance identifier
on object instantiation. It is very bad and all hell doors may get
loose if more than one reference to the same object, but if you are on
a time limit...
For a long right run it is not instance business to handle RMI (Remote
Method Invocation), they have to do their job right first. For RMI
there should be a separate dispatcher. This way an instance sends
request to the dispatcher with reference to itself as request
consumer. The dispatcher then handles the request queue and returns
results to consumers by stored references.
This way you don't care what identifier(s) is(are) currently used to
hold a reference to the object which is the proper way to do things.