| 123456789101112131415161718192021222324252627282930 |
- "use strict";
- (function () {
- class Person {
- constructor(name, age) {
- this.name = name;
- this.age = age;
- }
- say() {
- console.log("你好啊");
- }
- }
- /**
- * 因为想让多个子类同时拥有父类的属性和方法 所以采用继承
- * 继承后 子类会拥有父类相同的内容
- * 若子类中 定义的方法与父类相同 则会覆盖父类的方法 称为 方法重写
- *
- */
- class A extends Person {
- say() {
- console.log("大家好");
- }
- back() {
- console.log("返回");
- }
- }
- let a1 = new A("孙悟空", 10);
- console.log(a1, 'a1');
- a1.say();
- a1.back();
- })();
|