🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
在Haxe标准库中的一些类适用于静态扩展用法。下面的例子展示了StringTools的用法: > Several classes in the Haxe Standard Library are suitable for static extension usage. The next example shows the usage of StringTools: ~~~ using StringTools; class Main { static public function main() { "adc".replace("d", "b"); } } ~~~ String本身并没有替换功能, using StringTools 静态扩展提供了一个。通常,JavaScript输出很好的显式了这个转换: > While String does not have a replace functionality by itself, the using StringTools static extension provides one. As usual, the JavaScript output nicely shows the transformation: ~~~ Main.main = function() { StringTools.replace("adc","d","b"); } ~~~ 如下Haxe标准库中的类都是设计作为静态扩展使用: > The following classes from the Haxe Standard Library are designed to be used as static extensions: **StringTools**:提供字符串的扩展功能,例如替换和去除空格。 **Lambda**:提供功能方法到可迭代对象。 **haxe.EnumTools**:提供类型信息功能到enum和它们的实例。 **haxe.macro.Tools**:为和宏有关的操作提供不同的扩展(查看 工具(第9.4节)) > **StringTools**: Provides extended functionality on strings, such as replacing or trimming. > **Lambda**: Provides functional methods on iterables. > **haxe.EnumTools**: Provides type information functionality on enums and their instances. > **haxe.macro.Tools**: Provides different extensions for working with macros (see Tools (Section 9.4)). **使用using** >[warning] **花絮**:使用using 自从using关键字被添加到语言中,讨论某些 使用using的问题 或者 using的影响变得非常常见。在很多情况下的英语变得尴尬,所以手册的作者决定把这个使用实际的功能称呼:静态扩展。 >[warning] **Trivia**: “using” using Since the using keyword was added to the language, it has been common to talk about certain problems with “using using” or the effect of “using using”. This makes for awkward English in many cases, so the author of this manual decided to call the feature by what it actually is: Static extension. **大意可能就是说,using是作为静态扩展的关键字存在。如果本节标题使用 using using 会造成混淆。**