【发布时间】:2023-04-08 15:33:01
【问题描述】:
Operation 类创建一个这样的数组,数组前没有类名。
[operInputQuery[0].value, operInputQuery[1].value, operInputQuery[2].value]
'Table' 类旨在成为继承Operation 的构造函数的未命名类。
它可以正确继承,但是,它会像这样使用不必要的标签extends 创建数组。
extends[operInputQuery[0].value, operInputQuery[1].value, operInputQuery[2].value, operInputQuery[3].value]
是的,我不想用“扩展”的东西创建数组。
如何创建一个未命名的扩展类?
let Operation = class { //unamed class
constructor(a, b, c) {
this.a = operInputQuery[0].value;
this.b = operInputQuery[1].value;
this.c = operInputQuery[2].value;
}
}
let Table = class extends Operation { //purposed to write an unnmaed extended class
constructor(a, b, c, d){
super(a, b, c);
this.a;
this.b;
this.c;
this.d = operInputQuery[3].value;
}
};
【问题讨论】:
-
为什么要在构造函数中传入 a、b、c 并为它们赋值?这里似乎有些不对劲。另外,operInputQuery 是什么?
-
问题是如何创建未命名的扩展类。
-
类可以是匿名的,就像函数一样。数组是如何创建的?即使类有一个名字,它也会以某种方式在它前面加上一个名为的类是没有意义的
标签: javascript class unnamed-class