gpt4 book ai didi

javascript - 在 TypeScript 中将类转换为模块

转载 作者:行者123 更新时间:2023-11-28 03:59:57 25 4
gpt4 key购买 nike

我有一个类:

class Dice {
div: Element;
value: string;
constructor(div: Element) {
this.div = div;
}
}

我有 diceRoller 类扩展了 Dice 类:

class diceRoller extends Dice {
static Values = Values;
constructor(div: Element) {
super(div);
(this.div as HTMLElement).style.width = diceSize;
(this.div as HTMLElement).style.height = diceSize;
(this.div as HTMLElement).style.textAlign = 'center';
(this.div as HTMLElement).style.lineHeight = diceSize;
(this.div as HTMLElement).style.border = diceBorder;
(this.div as HTMLElement).style.marginRight = '10px';
(this.div as HTMLElement).style.cssFloat = 'left';
}
changeValue(val: number): boolean {
this.value = Values[val];
(this.div as HTMLElement).innerHTML = this.value;
return true;
}
}

如何将diceRoller 类转换为模块。我已经尝试了 TypeScript 手册中的所有方法,但我还没有弄清楚。

最佳答案

I want to export the class with the form similar to export {new diceRoller(div: Element)} because I want to pass an argument to the class in the file that I import the module in. so, what is exactly the form

简单地说:

export const foo = new diceRoller(div);

关于javascript - 在 TypeScript 中将类转换为模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47214322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com