1.使用call和apply完成属性的继承
2用原型链的方法实现方法的继承
function Person(name, age) {
this.name = name;
this.age = age;
}
//方法
Person.prototype.say = function() {
console.log(this.name + " 在哈哈大笑");
}
function Student(no, name, age) {
this.no = no;
// Person.call(this, name, age); //对象冒充
Person.apply(this, [name, age]);
}
//将父类的对象实例(new Person())赋值给子类的原型对象( Student.prototype)
// Student.prototype = new Person();//原型链继承
Student.prototype = new Person();
Student.prototype.study = function() {
console.log(this.name + " 打瞌睡");
}
var s = new Student(1000, '小刚', 6);
console.log(s);
s.say()