Object id, hash, etc?

Mark S. Miller erights at google.com
Tue Sep 8 21:07:52 UTC 2015


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.



>    }
>    return this[ identity ];
>   }
>  } );
>
> On Tue, Sep 8, 2015 at 1:44 PM, Mark S. Miller <erights at google.com> wrote:
>
>> See Labeler at
>> http://wiki.ecmascript.org/doku.php?id=harmony:weak_maps#unique_labeler
>>
>>
>>
-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150908/3cb9aa9f/attachment.html>


More information about the es-discuss mailing list