12345678910111213141516171819202122232425262728293031 |
- "use strict";
- // (function(){})()
- (function () {
- class Money {
- constructor(name, num) {
- this.name = name;
- this.num = num;
- }
- say() {
- console.log("你好");
- }
- }
- /**
- * super
- * 如果子类要使用父类中属性
- * 子类的构造函数必须对父类的构造函数重新进行接受
- * 使用super
- */
- class A extends Money {
- constructor(name, num, age) {
- super(name, num);
- this.age = age;
- }
- }
- class B extends Money {
- }
- let a = new A('喜羊羊', 100, 18);
- let b = new B('灰太狼', 50);
- console.log(a, 'a');
- console.log(b, 'b');
- })();
|