原型链
Grand.prototype.lastName = '张三';
function Grand(){
}
var grand = new Geand();
Father.prototype = grand;
function Father(){
this.name = '王五';
}
var father = new Father();
Son.prototype = father;
function Son(){
this.hobbit = '赵六';
}
var son = new Son()
坑1.
Person.prototype = {
height: 100,
}
function Person (){
this.eat = function (){
this.height ++;
}
}
var person = new Person()
person.eat()
//Person.prototype上面的height不会变,person自身上面会添加一个heigh:101
坑2.
绝大多数对象最终都会继承自Object.prototype
例外:
var obj = Object.create(null) // 它没有原型