What is the `using` keyword in Haxe? -


i see people use keyword using in haxe code. seem go after import statements.

for example, found code snippet:

import haxe.macro.context; import haxe.macro.expr; import haxe.macro.type; using haxe.macro.tools; using lambda; 

what , how work?

the "using" mixin feature of haxe referred "static extension". it's great syntactic sugar feature of haxe; can have positive effect on code readability.

a static extension allows pseudo-extending existing types without modifying source. in haxe achieved declaring static method first argument of extending type , bringing defining class context through using keyword.

take @ example:

using test.stringutil;  class test {     static public function main() {         // possible because of `using`         trace("haxe great".getwordcount());          // otherwise had type         // trace(stringutil.getwordcount("haxe great"));     } }  class stringutil {     public static inline function getwordcount(value:string) {         return value.split(" ").length;     } } 

run example here: http://try.haxe.org/#c96b7

more in haxe documentation:


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -