web类 继承Person类 原型链+对象冒充的组合继承模式
对象冒充的方式实现继承
function Person() {
this.name = "志杰啊";
this.age = 20;
this.run = function () {
console.log(666)
}
};
Person.getInfo = function () {
console.log("添加静态方法!")
}
function Web() {
Person.call(this);
}
var w = new Web();
w.run();
w.work();
es5 里面原型链实现继承
function Person() {
this.name = "志杰啊";
this.age = 20;
this.run = function () {
console.log(666)
}
};
Person.prototype.sex = "男";
Person.prototype.work = function () {
console.log(this.name + "在认真学习typescript")
}
function Web() {
};
Web.prototype = new Person();
var w = new Web();
w.run();
console.log(w.name)
w.work();