Is there any kind of hash code function in JavaScript?

后端 未结 20 1212
慢半拍i
慢半拍i 2020-12-04 09:59

Basically, I\'m trying to create an object of unique objects, a set. I had the brilliant idea of just using a JavaScript object with objects for the property names. Such as,

20条回答
  •  醉话见心
    2020-12-04 10:36

    The JavaScript specification defines indexed property access as performing a toString conversion on the index name. For example,

    myObject[myProperty] = ...;
    

    is the same as

    myObject[myProperty.toString()] = ...;
    

    This is necessary as in JavaScript

    myObject["someProperty"]
    

    is the same as

    myObject.someProperty
    

    And yes, it makes me sad as well :-(

提交回复
热议问题