Re: new

Tue, 11 Oct 2011 15:38:42 -0700

If they are just a different way of initializing, then I love Smalltalk’s 
approach of separating instantiation and initialization. E.g.
new Point.zero()
would actually mean (note: in normal JS, I always write parens after a 
new-invoked function, but here it works well)
(new Point).zero()

(new Point) just creates an empty instance. Several initialization methods set 
them up correctly.


What is missing from this approach is how to encapsulate the use of a subclass 
(as in Expression.parse which might return an instance of any subclass of 
Expression, depending on what is parsed – a literal, a binary operator, etc.). 
But maybe that should just be a function, e.g. parseExpression().


On Oct 12, 2011, at 0:29 , Jake Verbaten wrote:

> Point.zero = function () {
>   return (new Point).{ x: 0, y: 0 };
> }
> 
> why are factory methods special? they are just methods.
> 
> 
>> On Oct 11, 2011 11:26 PM, "Axel Rauschmayer" <a...@rauschma.de> wrote:
>> 
>> I absolutely love it for its conceptual beauty, but the primary goal should 
>> be to establish a single dominant way of doing inheritance in JavaScript.
>> 
>> One feature that doesn’t yet fit into my "pure OO" universe are factory 
>> functions/methods (I used frequently used factory methods in Java):
>> 1. They give better names to constructors.
>> 2. They allow one to return an instance of a subclass.
>> 
>> Example of #1: new Point.zero()
>> Example of #2: Expression.parse()
>> 
>> How would you add that to JavaScript?
>> On Oct 12, 2011, at 0:12 , Allen Wirfs-Brock wrote: > > On Oct 11, 2011, at 
>> 1:46 PM, Jake Verbate...
>> 
>> --  Dr. Axel Rauschmayer a...@rauschma.de twitter.com/rauschma home: 
>> rauschma.de
>> 
>> blog: 2ality.com
>> 
>> 
>> 
> 

-- 
Dr. Axel Rauschmayer

a...@rauschma.de
twitter.com/rauschma

home: rauschma.de
blog: 2ality.com



_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to