Haxe是通过引用传递参数还是复制?

SMK*_*MKS 6 haxe haxeflixel

拿这个代码:

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();
}
Run Code Online (Sandbox Code Playgroud)

'textureAtlas'是通过引用传递还是被复制?

http://api.haxeflixel.com/flixel/util/loaders/SparrowData.html

我知道PHP通过引用传递对象,除非另有说明(以&为前缀),否则会复制像Arrays这样的东西.Haxe同样适用吗?

谢谢.

Jus*_*ado 5

AFAIK,Primitives(Int,Float,Bool,...)按值传递.其他所有内容都通过引用传递.

  • 可以认为"基元"也通过引用传递.只是它们是不可变的,这意味着ref/value甚至不重要. (5认同)