var sx:Int = 10; var sy:Int = 20; private function call(fn:Void->Void):Void{ fn(); } private function gogo(xx:Int,yy:Int):Void{ trace("xx:"+xx,"yy:"+yy); trace("sx:"+sx,"sy:"+sy); } call(gogo.bind(sx,sy));
输出:xx:10 yy:20
sx:10 yy:20
Timer.delay(gogo.bind(sx,sy),1000); //call(gogo.bind(sx,sy)); sx= sy = 10;
输出:xx:10 yy:20
sx:10 sy:10
绑定时数值类型的数据会直接传入数值,那么引用类型的呢?
sp= new FlxSprite(); _testGroup.add(sp);//一个displayobjectcontainer call(gogo.bind(sp)); Timer.delay(gogo.bind(sp),1000); sp.alpha = 0; var sp:FlxSprite; private function call(fn:Void->Void):Void{ fn(); } private function gogo(sp:FlxSprite):Void{ trace("alpha"+sp.alpha); }
输出:alpha1
alpha0
结论:基本数据类型传的是当时的数据,引用类型的变量传的是引用
时间: 2024-10-08 01:39:24