Skip to content

Instantly share code, notes, and snippets.

@phylake
Last active December 16, 2015 17:29
Show Gist options
  • Save phylake/5470588 to your computer and use it in GitHub Desktop.
Save phylake/5470588 to your computer and use it in GitHub Desktop.
closure challenge
package
{
import flash.display.Sprite;
import flash.events.Event;
/**
* 1. What will be printed to the console (via the trace statement)?
* 2. What is the value of this inside of nested()
*/
public class Main extends Sprite
{
public function Main():void
{
push();
print();
}
private var v:Vector.<Function> = new Vector.<Function>;
public function push():void
{
var i:int = 2;
while (i--)
v.push(nested);
function nested(...rest):void
{
var str:String = String(i + rest[0]);
trace(str);
}
}
public function print():void
{
var f:Function;
while (f = v.shift()) f.apply(this, [1]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment