13.2.2 [[Construct]], constructor, and [[Class]] (was __proto__)

P T Withington ptw at pobox.com
Mon Sep 24 04:47:27 PDT 2007

On 2007-09-23, at 14:14 EDT, Brendan Eich wrote:

>> But for ES3 and real web compatibility, I don't think changing the
>> algorithm to not allow ordinary ES3 functions used as constructors to
>> return objects other than the one set up by [[Construct]] will work.
> Right, this will break the web. Tucker can weigh in on the
> workarounds OpenLaszlo needed to cope with the instance of this bug
> in Flash (AS2, and I think AS3 still, do not let a function return a
> different object from the one passed in as this when called via new).

The particular case that bit us was trying to create a portable  
'inherited hash' (a constructor to create an object with another  
object as its [[proto]].  We wanted to write a constructor:

function InheritedHash(from) {
   if (from) {
     function xtor() {};
     xtor.prototype = from;
     return new xtor();
   return this;

We originally worked around this by rewriting all `new` calls in our  
compiler to be function calls instead.  Since this was the only case  
where we needed to be able to return an alternate object from a  
constructor, we eventually just replaced it with a factory and  
replaced all calls.

[InheritedHash may or may not be a good idea.  The original concept  
was that it was more efficient than copying all the values into a new  
hash -- sharing of values was not actually a requirement.]

More information about the Es4-discuss mailing list