Object id, hash, etc?

Mark S. Miller erights at google.com
Tue Sep 8 21:14:06 UTC 2015


Hi Tab, then you get the Labeler, which this message is responding to.

On Tue, Sep 8, 2015 at 2:12 PM, Tab Atkins Jr. <jackalmage at gmail.com> wrote:

> On Tue, Sep 8, 2015 at 2:07 PM, Mark S. Miller <erights at google.com> wrote:
> > On Tue, Sep 8, 2015 at 1:57 PM, Michael McGlothlin
> > <mike.mcglothlin at gmail.com> wrote:
> >>
> >> I try to keep it pretty simple. It's not fancy but the times you want
> fast
> >> and dirty information like this are the same times you don't want to
> have to
> >> define it manually.
> >>
> >>  Symbol.identity = Symbol( 'Symbol.identity' );
> >>  const identity = Symbol( 'identity' );
> >>  var OBJECT_ID = 0;
> >>  Object.defineProperty( Object.prototype, Symbol.identity, {
> >>   get: () => {
> >>    if ( !Object.hasOwnProperty.call( this, identity ) ) {
> >>     this[ identity ] = ++OBJECT_ID;
> >
> >
> > Does not work on frozen objects.
>
> Of course, it's trivial to switch it to WeakMap'ing the key.
>
> ~TJ
>



-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150908/06e27f39/attachment.html>


More information about the es-discuss mailing list