请补全JavaScript代码,完成类的继承。要求如下:
1. "Chinese"类继承于"Human"类
2. "Human"类实现一个函数"getName",返回该实例的"name"属性
3. "Chinese"类构造函数有两个参数,分别为"name"、"age"
4. "Chinese"类实现一个函数"getAge",返回该实例的"age"属性
<script type="text/javascript"> class Human { constructor(name) { this.name = name this.kingdom = 'animal' this.color = ['yellow', 'white', 'brown', 'black'] } // 补全代码 getName() { return this.name; } } // 补全代码 class Chinese extends Human{ // 构造函数 constructor(name, age) { // 从父类集成name属性 super(name); this.age = age; } // getAge方法 getAge() { return this.age; } } </script>
<!DOCTYPE html> <html> <head> <meta charset=utf-8> </head> <body> <script type="text/javascript"> class Human { constructor(name) { this.name = name this.kingdom = 'animal' this.color = ['yellow', 'white', 'brown', 'black'] } // 补全代码 getName() { return this.name; } } // 补全代码 class Chinese extends Human{ constructor(name,age){ super(); this.name = name; this.age = age; } getAge() { return this.age; } } </script> </body> </html>
class Human { constructor(name) { this.name = name this.kingdom = 'animal' this.color = ['yellow', 'white', 'brown', 'black'] } // 补全代码 } //方法通过原型链也是可以的 Human.prototype.getName = function(){ return this.name; } // 补全代码 class Chinese extends Human { constructor(name,age){ super(name); this.age = age; } //不要写成function getAge(){return this.age} getAge(){ return this.age; } }
<!DOCTYPE html> <html> <head> <meta charset=utf-8> </head> <body> <script type="text/javascript"> class Human { constructor(name) { this.name = name this.kingdom = 'animal' this.color = ['yellow', 'white', 'brown', 'black'] } // 补全代码 getName(){ return this.name } } // 补全代码 class Chinese extends Human { constructor(name,age){ super(name) this.age = age } getAge(){ return this.age } } new Chinese("yaohf",32) </script> </body> </html>
class Human { constructor(name) { this.name = name this.kingdom = 'animal' this.color = ['yellow', 'white', 'brown', 'black'] } // 补全代码 getName(){ return this.name } } // 补全代码 class Chinese extends Human { constructor(name,age){ super(name) this.age = age } getAge(){ return this.age } getName(){ return super.getName() } }
// 补全代码 getName() { return this.name } } // 补全代码 class Chinese extends Human{ constructor(name,age) { super(name) this.age = age } getAge() { return this.age } }
<!DOCTYPE html> <html> <head> <meta charset=utf-8> </head> <body> <script type="text/javascript"> class Human { constructor(name) { this.name = name this.kingdom = 'animal' this.color = ['yellow', 'white', 'brown', 'black'] } // 补全代码 getName(){ return this.name } } // 补全代码 super调用父级,extends继承 class Chinese extends Human{ constructor(name, age){ super(name) this.age = age } getAge() { return this.age } } </script> </body> </html>
class Human { constructor(name) { this.name = name this.kingdom = 'animal' this.color = ['yellow', 'white', 'brown', 'black'] } // 补全代码 getName() { return this.name } } // 补全代码 class Chinese extends Human { constructor(name, age) { super(name); this.age = age } getAge() { return this.age } }
<!DOCTYPE html> <html> <head> <meta charset=utf-8> </head> <body> <script type="text/javascript"> class Human { constructor(name) { this.name = name this.kingdom = 'animal' this.color = ['yellow', 'white', 'brown', 'black'] } // 补全代码 getName(){ return this.name } } // 补全代码 class Chinese extends Human{ constructor(name, age){ super(name) this.age = age } getAge(){ return this.age } } </script> </body> </html>
class Human { constructor(name) { this.name = name this.kingdom = 'animal' this.color = ['yellow', 'white', 'brown', 'black'] } // 补全代码 getName() { return this.name } } // 补全代码 class Chinese extends Human { constructor(name, age) { super(name) this.name = name this.age = age } getAge() { return this.age } }
class Human { constructor(name) { this.name = name this.kingdom = 'animal' this.color = ['yellow', 'white', 'brown', 'black'] } // 补全代码 getName () { return this.name } } // 补全代码 class Chinese extends Human { constructor (name, age) { super(name) this.age = age } getAge () { return this.age } }
class Human { constructor(name) { this.name = name this.kingdom = 'animal' this.color = ['yellow', 'white', 'brown', 'black'] } // 补全代码 getName() { return this.name } } // 补全代码 class Chinese extends Human { constructor(name, age) { super(name) this.age = age this.name = name; } getAge() { return this.age; } }
<!DOCTYPE html> <html> <head> <meta charset=utf-8> </head> <body> <script type="text/javascript"> class Human { constructor(name) { this.name = name this.kingdom = 'animal' this.color = ['yellow', 'white', 'brown', 'black'] } // 补全代码 getName(){ return this.name } } // 补全代码 class Chinese extends Human{ constructor(name,age){ super(name,age) this.age = age } getAge(){ return this.age } } </script> </body> </html>
class Human { constructor(name) { this.name = name this.kingdom = 'animal' this.color = ['yellow', 'white', 'brown', 'black'] } // 补全代码 getName(){ return this.name } } // 补全代码 class Chinese extends Human { constructor(name,age){ super(name) this.age = age } getAge(){ return this.age } }