Last active
December 16, 2015 17:29
-
-
Save phylake/5470588 to your computer and use it in GitHub Desktop.
closure challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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