Closed mstade closed 10 years ago
Just change it so each key/value pair is a vector of length two, where the first item is the key and the second is the value. This is how Clojure does it:
(seq {:name "King Hank" :job "Ranger's goalie"})
; ([:name "King Hank"] [:job "Ranger's goalie"])
Currently,
seq
will return objects when iterating over enumerable properties, where the only property on the returned object is the value of that iteration. For example:(NB: order isn't guaranteed, but this seems to be the result in node anyway.)
Now, this is all well and good, but there's still no easy way of getting the one and only property out of these objects without knowing the names in advance. As a solution, I'm thinking of adding two non-enumerable properties to these objects:
name
andvalue
(or just0
and1
to make it array-like?)That way, you could use
props.first.name
orprops.first.value
to get the name/value respectively without having to know anything upfront:Since these would be non-enumerable properties, the key/value pair objects returned by the
seq
should still be usable in object merging scenarios since those usually only work on own properties and not prototypes or non-enumerable properties.