本文介绍了什么是模拟在ActionScript 3.0传递按引用最彻底的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ActionScript 3.0中(我假设的Javascript和ECMAScript一般)缺乏传递按引用的原生类型,如整型。结果我发现得到的值从一个函数真的笨重了。什么是正常的模式来解决此问题?
Actionscript 3.0 (and I assume Javascript and ECMAScript in general) lacks pass-by-reference for native types like ints. As a result I'm finding getting values back from a function really clunky. What's the normal pattern to work around this?
例如,是否有实施的交换(INTA,INTB)一个干净的方式的在Actionscript中?
For example, is there a clean way to implement swap( intA, intB ) in Actionscript?
推荐答案
我认为最好的你能做的就是通过一个容器对象作为参数传递给一个函数,并更改该对象的某些属性的值:
I Believe the best you can do is pass a container object as an argument to a function and change the values of some properties in that object:
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);
这篇关于什么是模拟在ActionScript 3.0传递按引用最彻底的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!