An Introduction to JS-Ctypes

Brendan Eich brendan at mozilla.com
Sat Sep 17 22:17:31 PDT 2011


On Sep 18, 2011, at 1:14 AM, Brendan Eich wrote:

> On Sep 18, 2011, at 12:22 AM, Andrea Giammarchi wrote:
> 
>> On Sun, Sep 18, 2011 at 6:07 AM, Brendan Eich <brendan at mozilla.com> wrote:
>> 
>> Binary data does no such thing! The descriptors are per generated type-constructor, not per instance.
>> 
>> once you define a StructType how do create an instance ?
>> 
>> new Point2D({x: 0, y: 0});
> 
> p = new Point2D;
> p.x = 0;
> p.y = 0;

Default value is 0 so there' s no need for these assignments. If you have non-zero initial values, perhaps they are constant, in which case you can hoist the object literal out of any loops and make it a singleton (frozen even, denoted by a const).

The point is that you don't *have* to pass a fresh object literal to each constructor call.

/be

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110918/5b49b988/attachment.html>


More information about the es-discuss mailing list