Question about reusing object used in Object.defineProperty

Brendan Eich brendan at mozilla.com
Mon Sep 23 14:44:37 PDT 2013


I wouldn't worry about object literal allocations for such (typically 
one-time, up front) Object.defineProperty calls.

Also, es-discuss is not really the place to ask about how to write this 
code.

/be

> J B <mailto:port25 at gmail.com>
> September 23, 2013 2:40 PM
> *oops:
>
> obj.value = 0;
> Object.defineProperty(this, 'foo', obj);
> obj.value = 1;
> Object.defineProperty(this, 'foo2', obj);
>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
> J B <mailto:port25 at gmail.com>
> September 23, 2013 2:28 PM
> var obj = {};
>
> Object.defineProperty(this, 'foo', obj.value = 0);
> Object.defineProperty(this, 'foo2', obj.value = 1);
>
> vs.
>
> Object.defineProperty(this, 'foo', {value:0});
> Object.defineProperty(this, 'foo2', {value:1});
>
>
> Would the former method help with reducing object allocation (and 
> therefore gc), or are there compiler optimizations that will 
> automatically make the former as efficient?
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss


More information about the es-discuss mailing list