Assume the following program:
var SomeConstructor = function() { };
var instance = new SomeConstructor ();
The expression instance instanceof SomeConstructor yields True, so instance has to know somehow that it was constructed by the function SomeConstructor . Is there way to retrieve the name SomeConstructor directly from instance ?
(In my problem at hand, I have a hierarchy of prototypes implementing possible signals in my application. I have to access the type of a signal which shall be equivalent to the constructor used to create that signal.)
On Chrome (7.0.544.0 dev), if I do:
it prints ‘SomeConstructor’…but if SomeConstructor is defined as an unnamed function as you have it, it will print an empty string instead.
If I print
instance.constructorit prints the same thing as it does if I printSomeConstructorin the code you have. The instanceof operator need only compare these two values to see that they are equal to be able to returntrue.