写一个类Person,拥有属性age和name,拥有方法say(something)
再写一个类Superman,继承Person,拥有自己的属性power,拥有自己的方法fly(height)
// ES5
function Person (age, name) {
this.age = age
this.name = name
}
Person.prototype = {
say: function() {
console.log("hello");
}
};
var Superman = function(age, name, power) {
Person.call(this, age, name);
this.power = power;
};
Superman.prototype = new Person();
Superman.prototype.fly = function(height) {
console.log(height);
}
// ES6
class Person {
constructor(age, name) {
this.age = age;
this.name = name;
}
say () {
console.log("hello");
}
}
class Superman extends Person {
constructor (age, name, power) {
super(age, name);
this.power = power;
}
fly (height) {
console.log(height);
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。