Unicode字符可用作TypeScript函数名称中的省略号吗?

huangapple go评论78阅读模式
英文:

Unicode character to be used as an ellipsis in TypeScript function names?

问题

我正在开发一个代码生成器。它的源是为其他目的创建的特定XML文档。有时生成的函数名称太长了。我尝试了几种解决方案,但最终只能截断它们。现在我需要在名称中添加一些指示,表示发生了这种截断。

比如用省略号作为后缀:selectGrade1RestrictedInPhysicallyStrenuousActi…()

但在TypeScript函数中,省略号和点都不允许作为字符。有什么其他替代方法吗?

英文:

I am in the process of developing a code generator. Its sources are certain XML documents created for other purposes. Sometimes the generated function names are way too long. I have experimented with several solutions, but in the end I just have to crop them. Now I need some indicator in the name that such a cut happened.

Like an ellipsis as suffix: selectGrade1RestrictedInPhysicallyStrenuousActi…()

But neither ellipsis nor dots are allowed as characters in a TypeScript function. Any idea what to use instead?

答案1

得分: 0

我找到的目前最好的是希腊字符 ·,看起来像一个点。用法:selectGrade1RestrictedInPhysicallyStrenuousActi···()

根据 ECMAScript 6 / Unicode 8.0.0,这是一个有效的标识符。

但是,根据 ES5 的标准,这不是一个有效的标识符。如果要支持旧版本的 JavaScript 引擎,您可能希望避免使用它。

https://mothereff.in/js-variables#selectGrade1RestrictedInPhysicallyStrenuousActi%C2%B7%C2%B7%C2%B7

幸运的是,Visual Studio Code 对这个字符没有任何投诉。不像 ͺ

英文:

The best I found so far is the greek character · which looks like a dot. Usage:
selectGrade1RestrictedInPhysicallyStrenuousActi···()

> That’s a valid identifier according to ECMAScript 6 / Unicode 8.0.0.
>
> However, it is not a valid identifier as per ES5. You may want to avoid it if support for older JavaScript engines is a concern.

https://mothereff.in/js-variables#selectGrade1RestrictedInPhysicallyStrenuousActi%C2%B7%C2%B7%C2%B7

Fortunately Visual Studio Code does not complain at all about that character. Unlike e. g. ͺ.

huangapple
  • 本文由 发表于 2023年7月10日 19:16:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76653181.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定