The other constructors: Object.create() and String.fromCharCode()

Peter Michaux petermichaux at gmail.com
Sun Jun 5 11:00:11 PDT 2011


ES has "new Constructor()" as its basic syntax for construction. This
means that if other constructors are also beneficial that the syntax
to call them is inconsistent. For example, ES3 had the
"String.fromCharCode" and ES5 added "Object.create". These are both
constructors of sorts. Would it be possible to add "String.new" etc so
that construction is consistent?

Unfortunately Date.now, Date.parse, Date.UTC don't return Date objects
as they would be elegant cases of being other constructors.

Yes in order to get consistent syntax, host objects would need to
implement the static "new" method.

(I remember the idea of being able to write "String.new" rather than
having to write "String['new']" was discussed in the past. I don't
know if keywords as bare object keys are allowed in ECMAScript but it
seems to work in Firefox.)

Peter


More information about the es-discuss mailing list