obsoleting the "new" keyword

Peter Michaux petermichaux at gmail.com
Mon Jan 19 10:27:28 PST 2009


On Sun, Jan 18, 2009 at 4:35 PM, Brendan Eich <brendan at mozilla.com> wrote:
> On Jan 17, 2009, at 12:51 PM, Peter Michaux wrote:

> // Assume classes as sugar definition of class C
> Object.defineProperty(C, 'new',
>                      { enumerable: false, configurable: false, writable:
> false,
>                        value: function () { return C.apply(null, arguments);
> }.bind(C) });
>
> Of course this seems like much ado about nothing, because classes as sugar
> mean C is a factory function, so you could just write
>
> var pts = getRows().map(Point);
>
> Again, if the class always constructs when invoked, why do we need .new?
>
> One answer might be for classes that do not construct when invoked.

That is the answer.

> For
> better or worse, the core language and common embedding objects have class
> constructor functions that do not construct when invoked without operator
> new.

By "obsolete" the "new" operator, I did not mean remove it from the
language. I meant make using "new" the less preferred way to have a
constructor function work as a constructor rather than a regular
function call. In order to make "new" the less preferred way, a
uniform way (possibly like String.new and Point.new) could be added to
the language so that the "new" operator can stay in place but would be
"community deprecated". Does that make sense?

Peter


More information about the Es-discuss mailing list