123456789101112131415161718192021222324252627282930313233343536 |
- "use strict";
- // (function(){})()
- (function () {
- class Money {
- constructor(name, num) {
- this.name = name;
- this.num = num;
- }
- say() {
- console.log("你好");
- }
- }
- /**
- * 继承 extends
- * 因为想让多个子类同时拥有父类的属性或方法 所以产生继承
- * 继承后 子类会拥有父类相同的内容
- * 子类中 若出现与父类相同的方法 则进行覆盖
- * 子类中 若出现与父类不相同的方法 则执行新方法
- */
- class A extends Money {
- say() {
- console.log("我叫a");
- }
- hello() {
- console.log("haha");
- }
- }
- class B extends Money {
- }
- let a = new A('喜羊羊', 100);
- let b = new B('灰太狼', 50);
- console.log(a, 'a');
- console.log(b, 'b');
- a.say();
- a.hello();
- })();
|