// 函数执行的的安全模式,可以省去new直接创建使用
var book = function(id,name,price){
// 判断执行过程中this是否是当前这个对象(如果是说明是用new创建的)
if(this instanceof book){
this.id = id;
this.name = name;
this.price = price;
}else{
return new book(id,name,price);
}
}
// 函数执行的的安全模式,可以省去new直接创建使用
var book = function(id,name,price){
// 判断执行过程中this是否是当前这个对象(如果是说明是用new创建的)
if(this instanceof book){
this.id = id;
this.name = name;
this.price = price;
}else{
return new book(id,name,price);
}
}