function Person(name,age){
console.log(this)
this.names=name;
this.age=age;
Person.prototype.say=function(){
return this.names+"是xx";
};
this.xx=function(){
return this.names+"是xx";
};
}
var b=new Person("a",12)
var c=new Person()
console.log(b.say==c.say)
console.log(b.xx==c.xx)
+++++++++++++++++++++++++++++++++++++++++++++++
function Person(){
// Person.prototype.names=["123","456"];
}
Person.prototype.names=["123","456"];
Person.prototype={
age:12,
word:"12",
}
var b=new Person()
console.log(b.names)
console.log(b.names)
var c=new Person()
console.log(c.names)
c.names.push("789")
console.log(b.constructor)
console.log(c.names)
function Person(){
Person.prototype.names=["123","456"];
}
// Person.prototype.names=["123","456"];
//原型不要写入构造函数内,否则会被实例化;
Person.prototype={
age:12,
word:"12",
names:["a","b","c"],
}
var c=new Person()
var b=new Person()
console.log(b.names)
console.log(b.names)
console.log(c.names)
c.names.push("789")
console.log(b.constructor)
console.log(c.names)