js
这门傻逼的语言真让人头大!
如何实现js
的继承?
function Base(name) {
this.name = name;
this.getName = function () {
return this.name;
}
}
function Child(age) {
this.age = age;
this.getAge = function () {
return this.age;
}
}
Child.prototype = new Base("base"); // 实现继承
var ch = new Child(16);
console.log("age = " + ch.getAge() + " , name = " + ch.getName());
// 输出: age = 16 , name = base
也不解释了,反正我也解释不好。