列表

详情


JS13. 类继承

描述

请补全JavaScript代码,完成类的继承。要求如下:
1. "Chinese"类继承于"Human"类
2. "Human"类实现一个函数"getName",返回该实例的"name"属性
3. "Chinese"类构造函数有两个参数,分别为"name"、"age"
4. "Chinese"类实现一个函数"getAge",返回该实例的"age"属性

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 1683ms, 内存消耗: 77796KB, 提交时间: 2022-02-09

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n            class Human {\n                constructor(name) {\n                    this.name = name\n                    this.kingdom = 'animal'\n                    this.color = ['yellow', 'white', 'brown', 'black']\n                }\n                // 补全代码\n                getName(){\n                    return this.name;\n                }\n            }\n\n            // 补全代码\n            class Chinese extends Human{\n                constructor(name,age){\n                    super(name);\n                    this.age = age;\n                }\n                 getAge(){\n                    return this.age;\n                }\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1747ms, 内存消耗: 77804KB, 提交时间: 2022-01-03

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n            class Human {\n                constructor(name) {\n                    this.name = name\n                    this.kingdom = 'animal'\n                    this.color = ['yellow', 'white', 'brown', 'black']\n                }\n                // 补全代码\n                 getName () {\n                  return this.name\n                }\n            }\n\n            // 补全代码\n            class Chinese  extends Human{\n                constructor(name,a){\n                    super(name)\n                    this.a = a\n                }\n                getAge() {\n                    return this.a\n                }\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1749ms, 内存消耗: 77864KB, 提交时间: 2022-01-25

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n            class Human {\n                constructor(name) {\n                    this.name = name\n                    this.kingdom = 'animal'\n                    this.color = ['yellow', 'white', 'brown', 'black']\n                }\n                // 补全代码\n                getName(){\n                    return this.name;\n                }\n            }\n\n            // 补全代码\n            class Chinese extends Human {\n                constructor(name, age) {\n                    super(name);\n                    this.age = age;\n                }\n                \n                getAge(){\n                    return this.age;\n                }\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1751ms, 内存消耗: 77860KB, 提交时间: 2022-01-22

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n            class Human {\n                constructor(name) {\n                    this.name = name\n                    this.kingdom = 'animal'\n                    this.color = ['yellow', 'white', 'brown', 'black']\n                }\n                // 补全代码\n               getName(){\n                   return this.name\n               } \n            }\n\n            // 补全代码\n            class Chinese extends Human{\n                constructor(name,age){\n                    super(name)\n                    this.age = age;\n                }\n                getAge(){\n                    return this.age\n                }\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1752ms, 内存消耗: 77772KB, 提交时间: 2021-12-11

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n            class Human {\n                constructor(name) {\n                    this.name = name\n                    this.kingdom = 'animal'\n                    this.color = ['yellow', 'white', 'brown', 'black']\n                }\n                // 补全代码\n                getName(){\n                    return this.name\n                }\n            }\n\n            // 补全代码\n            class Chinese  extends Human{\n                constructor(name ,age){\n                    super(name)\n                    this.age=age\n                }\n                getAge(){\n                    return this.age\n                }\n            }\n        </script>\n    </body>\n</html>","libs":[]}

上一题