关于函数参数
关于函数参数
如果传递的参数是Object类型的,那么参数将以引用的形式传递,否则传递的只是一个拷贝。注意Array类型也是Object类型。
例子:(数组作为参数)
ActionScript Code:
- var testAry:Array = [1,4,0,5,3];
- function changeAry(ary:Array)
- {
- ary[0] = 6;
- }
- trace("函数调用前内容是 " + testAry[0])
- changeAry(testAry);
- trace("函数调用后内容是 " + testAry[0])
输出结果是
Output Code:
- 函数调用前内容是 1
- 函数调用后内容是 6
Object最为参数:
ActionScript Code:
- var testAry:Array = [1,4,0,5,3];
- var testObj:Object = new Object()
- testObj.x = 10;
- function changeObj(obj:Object)
- {
- obj.x = 20
- }
- trace("函数调用前内容是 " + testObj.x)
- changeObj(testObj)
- trace("函数调用后内容是 " + testObj.x)
输出结果是:
Output Code:
- 函数调用前内容是 10
- 函数调用后内容是 20
字符串作为参数:
ActionScript Code:
- var testStr:String = "Hello World!";
- function changeStr(str:String)
- {
- str = "Good Bye!"
- }
- trace("函数调用前内容是 " + testStr)
- changeStr(testStr)
- trace("函数调用后内容是 " + testStr)
输出结果是
Output Code:
- 函数调用前内容是 Hello World!
- 函数调用后内容是 Hello World!

Leave a Reply