2 new出的对象

对象没有原型对象,函数才有
new出的对象,this的会重新创建,二prototype并不会重新创建,而是追溯原型链的方式进行继承
var Book=function(id,bookname,price){
this.id=id;
this.hh = function () { console.log("hh执行了")}
return this;
}
Book.prototype.dispay=function(){console.log("111111111")}
let che=new Book(2);
console.log(che)
console.log(che.id, 'id')
console.log(che.hh, 'hh函数')
che.hh()
console.log(che.prototype)
console.log(che.dispay)
che.dispay()

猜你喜欢

转载自www.cnblogs.com/dianzan/p/10794354.html