Re: new

Tue, 11 Oct 2011 15:45:16 -0700

As for expression.parse, any constructor or initializer is still a function
therefore it can return an object thats not this.

This would be a good usecase for overwriting the [[Prototype]] with a new
value.

I dont know what sugar or syntax other languages with "factory methods"
offer which makes the ordeal significantly more elegant.

On Oct 11, 2011 11:38 PM, "Axel Rauschmayer" <a...@rauschma.de> wrote:

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 Poi...
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to