On Oct 11, 2011, at 4:03 PM, Kevin Reid wrote:
>>
>
> Well, in JavaScript you can always Object.create(Point.prototype, ...).
>
> In Java, for example, the ability to have multiple constructors can be very
> convenient for that type of use case; but it always can be replaced with
> factory methods and a private constructor with more parameters.
>
> Actually, my original remark may be off-base anyway; I haven't followed the
> discussion well enough. If the ".{" syntax returns a new object rather than
> mutating one, then I was confused.
No, you were exactly correct. .{ mutates the object to the left of the .
> Point.zero = function () {
> return (new Point).{ x: 0, y: 0 };
> }
return (new Point).{x: 0, y: 0};
is essentially short hand for:
let p = new Point.
p.x = 0;
p.y = 0;
return p;
of course, you entire definition above could have alternatively been written as:
Point.{zero() {return (new Point).{x:0, y: 0}};
Allen
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss