prototype for operator proposal for review

Luke Hoban lukeh at
Tue May 17 23:46:16 PDT 2011

> The primary scenario is what some people call "subclassing" the various built-in classes of objects that have special internal state and behavior. The most important of these "classes" are Array, Function, and RegExp.  Programmer want to be able to create instances of these whose direct [[Prototype]] is different from the default. (in most cases the desired prototype will inherit from the default)

I was assuming that similar library functions such as Array.make, Function.make and RegExp.make would address these cases in the same way as Object.make.  Beyond the intermediate object allocation issue, is there anything else those cannot accomplish?  Either way, exposing the library function alternatives as well seems useful to provide the capability to subclass these objects in 'text/javascript'.

> An implementation might try to optimize such functions as you describe, but because both the global binding to the base  object and the property binding of the method are mutable you at least have to have a dynamic guard on any fast path and still have to generate the code to create the arguments and do a regular call if the guard fails.  I made the same argument for Object.create and I'm not aware of implementation that have yet to optimize it in this manner.

Fair enough.  I'll check on whether we have considered any similar optimizations in IE.

More information about the es-discuss mailing list