Suggest Object.compare(lert, right)

Michał Wadas michalwadas at gmail.com
Mon Sep 19 09:03:24 UTC 2016


On Mon, Sep 19, 2016 at 7:32 AM, Park Hyeonu <nemo1275 at gmail.com> wrote:

> I'm sure this feature is already implemented for every modern js engines,
> as it's needed to implement Map/Set.
>

But you know that, it's indeterministic and implementation is free to
reorganize pointers?

a = {}; b = {};
Object.compare(a,b); // 1
gc.enforceGC();
Object.compare(a,b); // -1

So any userland structure can't rely on persistence of order.

Moreover, such ordering can be implemented with WeakMap.

const wm = new WeakMap()
let i = 0;
function getId(obj) {
    if (!wm.has(obj))
        wm.set(obj, i++);
    return wm.get(obj);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160919/1ade57dd/attachment-0003.html>


More information about the es-discuss mailing list