写一个类Person,拥有属性age和name,拥有方法say(something)
再写一个类Superman,继承Person,拥有本身的属性power,拥有本身的方法fly(height)this
// ES5 function Person (age, name) { this.age = age this.name = name } Person.prototype = { say: function() { console.log("hello"); } }; var Superman = function(name, age, power) { Person.call(this, name, age, power); 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); } }