クロージャってこういうこと?
/**
* Copyright paq ( http://wonderfl.net/user/paq )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/7of6
*/
package {
import flash.display.Sprite;
import flash.text.TextField;
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
var t:TextField = new TextField();
t.height=465
addChild(t)
function closure():Function{
var n:int = 0;
return function():void{
n++;
t.appendText(n.toString()+"\n");
}
}
var f:Function = closure();
f();
f();
f();
f();
t.appendText("---------------\n");
(function():Function{
var n:int = 0;
return function():Function{
n++;
t.appendText(n.toString()+"\n");
return arguments.callee
}()
})()()()()
t.appendText("---------------\n");
(function():Function{
var n:int = 0;
return function():Function{
n++;
t.appendText(n.toString()+"\n");
return function():Function{
n+=2;
t.appendText(n.toString()+"\n");
return function():Function{
n+=3;
t.appendText(n.toString()+"\n");
return function():Function{
n+=4;
t.appendText(n.toString()+"\n");
return function():void{
n+=5;
t.appendText(n.toString()+"\n");
}
}
}
}
}()
})()()()()()
}
}
}