[]如何用ts对引擎类进行方法扩展
项目所需,里面大量脚本移植到Laya,其中有个环节叫扩展方法(Extension Method)。
一般的方法扩展,对Number类型添加thousandsSeperator:
declare global {
interface Number {
thousandsSeperator(): String;
}
}
Number.prototype.thousandsSeperator = function(): string {
return Number(this).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
export {};
我用同样的方法尝试了,但是行不通。
请问我的ts 3d项目中,我想对常用的引擎类进行方法扩展(Animtor, BaseRender, Vector3, 等等)
我应该怎么做,请求管理员的帮助,谢谢。
一般的方法扩展,对Number类型添加thousandsSeperator:
declare global {
interface Number {
thousandsSeperator(): String;
}
}
Number.prototype.thousandsSeperator = function(): string {
return Number(this).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
export {};
我用同样的方法尝试了,但是行不通。
请问我的ts 3d项目中,我想对常用的引擎类进行方法扩展(Animtor, BaseRender, Vector3, 等等)
我应该怎么做,请求管理员的帮助,谢谢。
要回复问题请先登录
1 个回复
Aar0n
赞同来自: