Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

1. Objects are sets of keys

2. JS has Map/Set which allow other composite types as keys and can be converted to objects for JSON serialization then deserialize back to Map/Set.



Yeah but still you have to admit, there's quite a lot more friction and ambiguity in that approach. Do I represent a map as

    [
      ["key", "value"],
      ["otherKey", "otherValue"]
    ]  
  
or

    [
      {"key": "key", "value": "value"},
      {"key": "otherKey", "value":"otherValue"}
    ]  
or something else? And how can I distinguish between values which just happen to look like maps but are actually not maps? And what if the service I'm talking to does it differently? What if I'm comparing or sorting two JSON values, don't I have to modify the equality/hashcode/ordering logic now to interpret

    [
      ["key", "value"],
      ["otherKey", "otherValue"]
    ] 
and

    [
      ["otherKey", "otherValue"],
      ["key", "value"]
    ] 
as being equal and implement a new hashcode/ordering which treats them as equal?

Quite a lot easier when this is just native to the format.


JS Map/Set use referential equality, which is pretty worthless if you aren't dealing with primitives.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: