6
把这个代码:Haxe通过引用传递参数还是复制副本?
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
/**
* @param lives
* @param corn
* @param textureAtlas
*/
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”获得通过引用传递或者它被复制?
http://api.haxeflixel.com/flixel/util/loaders/SparrowData.html
我知道PHP按引用传递对象,事情就是这样数组被复制,除非另有说明(与&前缀)。 Haxe也适用吗?
谢谢。
“原始材料”也可以考虑通过参考。它只是它们是不变的,这意味着通过ref/value甚至不重要。 –
实际上,我会说Haxe中的所有东西都是按值传递的,其中基本类型(Bool,Int,Float)直接复制到对象和其他类型的引用被复制的地方。 Bool,Int,Float和String总是不变的,并且通过值进行比较。无论是否复制字符串或复制引用,我认为它们都是特定于目标的,但由于它们是不可变的,所以它并不重要。 –