什么是在Actionscript 3.0中模拟传递引用的最简洁方法?

Mat*_*t W 13 actionscript-3

Actionscript 3.0(我假设Javascript和ECMAScript一般)缺少像int这样的本机类型的传递引用.结果我发现从功能上获得的价值真的很笨重.解决这个问题的正常模式是什么?

例如,是否有一种干净的方法在Actionscript中实现swap(intA,intB)

has*_*seg 7

我相信你能做的最好的事情是将一个容器对象作为参数传递给一个函数,并改变该对象中某些属性的值:

function swapAB(aValuesContainer:Object):void
{
    if (!(aValuesContainer.hasOwnProperty("a") && aValuesContainer.hasOwnProperty("b")))
        throw new ArgumentError("aValuesContainer must have properties a and b");

    var tempValue:int = aValuesContainer["a"];
    aValuesContainer["a"] = aValuesContainer["b"];
    aValuesContainer["b"] = tempValue;
}
var ints:Object = {a:13, b:25};
swapAB(ints);
Run Code Online (Sandbox Code Playgroud)