[英]What's the meaning of __new__ in Haxe for Flash?
I saw some code (written for Flash) that looks like this: 我看到一些代码(为Flash编写)看起来像这样:
var _array:Array<Int> = untyped __new__(Array, 10);
And I find it creates an Array
and with a length
of 10. However, when I try something like: 我发现它创建了一个Array
, length
为10.然而,当我尝试类似的东西:
var _array:Array<Int> = untyped __new__(Array, 1, 2);
It creates an Array
which has two elements. 它创建了一个包含两个元素的Array
。 I'm confused by this, what's the real meaning of __new__
? 我对此感到困惑, __new__
的真正含义是__new__
?
It is Haxe "magic", see the wiki . 这是Haxe的“魔力”,请参阅wiki 。
The __new__
is to call the native constructor, in the case of Array
, it is different from what Haxe exposes ( Array
in Haxe doc vs Array
in AS3 doc ). 该__new__
是调用本机的构造,在的情况下Array
,它是从什么HAXE公开(不同的Array
中HAXE DOC VS Array
在AS3 DOC )。
Basically using __new__
initializes the Array
with a length and/or values without manually doing: 基本上使用__new__
使用长度和/或值初始化Array
而无需手动执行:
var array = [];
for(i in 0...len) array.push(0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.