- Java (
System.identityHashCode
As far as reasonably practical, the hashCode method defined by the Object class returns distinct integers for distinct objects. (This is typically implemented by converting the object's internal address into an integer, but this implementation technique is not required by the Java programming language.)
- Python (
id
)
Returns the "identity" of an object. This is an integer (or long integer) that is guaranteed to be unique and constant for this object during its life cycle. Two non-overlapping objects can have the same value for id ().
Is there any similar functionality in JavaScript? Preferably standardized, that works in all browsers and other environments (Rhino, V8). Searching for "identity" I only find references to the operator ( ===
) ...
I know that some environments do not support this concept (.NET seems to not for optimization reasons ), but in This is not a problem because they are more complete languages, which have the concepts of destructor , finalizer and / or weak references . As far as I know, JavaScript does not support this, so a way to get a numeric value that uniquely represents an object would be very useful (a simple reference to the object does not help because it would prevent it from being collected as garbage.)