Created
March 18, 2017 16:49
-
-
Save YuRen-tw/a2695c454b0bd34a2d28dfa0192abfef to your computer and use it in GitHub Desktop.
Infinite Loop
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
function mkInfFuncToggle(func) { | |
var X = { x : 0 }; | |
function infFunc() { | |
func(); | |
if (X.x) { setTimeout(infFunc, 1); } | |
} | |
function infFuncToggle() { | |
if (X.x) { X.x = 0; } | |
else { | |
X.x = 1; | |
infFunc(); | |
} | |
} | |
return infFuncToggle; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment