偶然想起Javascript new 的结果到底是什么的问题,比如:var circle =new Shape( "circle" );
于是查了下ECMA-262-5.1标准。关键是这一步:Let result be the result of calling the [[Call]] internal property of F, providing obj as the this value and providing the argument list passed into [[Construct]] as args.
因此 不考虑异常情况的话上面的new就相当于:
var circle = {};
var temcircle = Shape.call(circle, "circle" );
if (typeof(temcircle)== "object"){
return temcircle;
}
return circle;