Suggest Object.compare(lert, right)

Park Hyeonu nemo1275 at gmail.com
Mon Sep 19 05:10:56 UTC 2016


tl;dr - deterministic function that compares arbitrary objects

I know now we have `Map` and `Set`, but sometimes we need more low level
ones. Especially for library developers.

For the case, say, I want to implement a map whose key can be a arbitrary
number of objects. Currently this can only implemented as nested map whose
structure is `keylen -> key1 -> key2 -> ... -> value`. Not really elegant.
But if we have `Object.compare()`, `(key1, key2, ...) -> value` is possible.

As its intended purpose is to be used with custom map/set, I don't think we
should define how this function works in spec. Just guaranteed to be
deterministic in each runtime is enough.

For detail, this function follows `(left: any, right: any) => number` form.
When `Object.is(left, right)` is true, `Object.compare(left, right)` must
return `0`. Otherwise, the result must be deterministic, means whenever(in
same runtime) we call this function with same arguments it should return
same value(or at least, always greater than/lesser 0).

Seems good?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160919/9a445e98/attachment-0002.html>


More information about the es-discuss mailing list