Haxe 是通过引用传递参数还是复制?
Does Haxe pass parameters by reference or does it make a copy?
取此代码:
function createGUIHud():Void
{
this.screen.gameHud = new NormalGameHud(10, 0, this.screen.getTextureAtlas());
this.screen.gameHud.x = FlxG.width - (this.screen.gameHud.width + GameSize.getPositionByPlatform(10));
this.screen.gameHud.y = GameSize.getPositionByPlatform(10);
}
// NormalGameHud.hx
public function new(lives:Int = 10, corn:Int = 0, textureAtlas:SparrowData)
{
super(0, 0, 30);
this.lives = lives;
this.cornCount = corn;
this.textureAtlas = textureAtlas;
this.createScoreboard();
this.createLivesCount();
this.createCornCounter();
}
textureAtlas
是通过引用传递还是复制?
我知道 PHP 通过引用传递对象,除非另有说明(前缀为 &
),否则数组之类的东西会被复制。这同样适用于 Haxe 吗?
AFAIK、Basic Types(Int
、Float
、Bool
)按值传递。其他所有内容均通过引用传递。
取此代码:
function createGUIHud():Void
{
this.screen.gameHud = new NormalGameHud(10, 0, this.screen.getTextureAtlas());
this.screen.gameHud.x = FlxG.width - (this.screen.gameHud.width + GameSize.getPositionByPlatform(10));
this.screen.gameHud.y = GameSize.getPositionByPlatform(10);
}
// NormalGameHud.hx
public function new(lives:Int = 10, corn:Int = 0, textureAtlas:SparrowData)
{
super(0, 0, 30);
this.lives = lives;
this.cornCount = corn;
this.textureAtlas = textureAtlas;
this.createScoreboard();
this.createLivesCount();
this.createCornCounter();
}
textureAtlas
是通过引用传递还是复制?
我知道 PHP 通过引用传递对象,除非另有说明(前缀为 &
),否则数组之类的东西会被复制。这同样适用于 Haxe 吗?
AFAIK、Basic Types(Int
、Float
、Bool
)按值传递。其他所有内容均通过引用传递。