var Color = function(color){
this.color = color
};
Color.prototype ={
show : function(){
console.log(this.color)
}
};
new Color("red");
console.log(new Color("red"));
console.dir(new Color("red"));
new 实例化一个函数,其内部模拟大致如下:
new Color("red") = function(){
/*===1===*/
var obj = {};
obj.__proto__ = Color.prototype;
/*===2===*/
var result = Color.call(obj,"red");
/*===3===*/
return typeof result ==="object"?result:obj;
}