13.2.2 [[Construct]]

2010-05-23

The Function.[[Construct]] property has the result of this method.

Code: (Meta Ecma)
function CreateFunctionConstruct(){
return function(args){
var obj = new Object; // this is a new instance of this class
// "set all internal methods of obj to 8.12"
obj.[[Class]] = "Object";
obj.[[Extensible]] = true;
var proto = this.[[Get]]("prototype");
if (Type(proto) == 'object') this.[[Prototype]] = proto;
else obj.[[Prototype]] = Object.prototype; // as defined in 15.2.4
var result = this.[[Call]](obj, args);
if (Type(result) == 'object') return result;
return obj;
};
}

Note that a constructor may return any other object to override returning the new object. If whatever you return in the constructor is NOT an object, however, your return value is ignored and the new instance is returned anyways.