functionPerson(){
}
functionAnimal(){
}
var person=new Person();
var animal=new Animal();
Person.prototype={
"name":"Mike",
sayName:function(){
console.log(this.name);
}
}
Animal.prototype.name="animal";
Animal.prototype.sayName=function(){
console.log(this.name);
}
person.sayName(); //error person.sayName is not a function
animal.sayName();//animal
分析:
functionPerson(){
}
functionAnimal(){
}
var person=new Person();
var animal=new Animal();
console.log(person.__proto__===Person.prototype); //true
console.log(animal.__proto__===Animal.prototype); //true
Person.prototype={
"name":"Mike",
sayName:function(){
console.log(this.name);
}
}
Animal.prototype.name="animal";
Animal.prototype.sayName=function(){
console.log(this.name);
}
console.log(person.__proto__===Person.prototype); //false
console.log(animal.__proto__===Animal.prototype); //true
person.sayName(); //error person.sayName is not a function
animal.sayName();//animal