Created
December 22, 2010 03:59
-
-
Save michaelficarra/751068 to your computer and use it in GitHub Desktop.
fully transparent closure-wrapping of loop bodies, showcasing all features
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
| fns = [] | |
| for k, v of obj | |
| continue if k is 0 | |
| break if k is 1 | |
| fns.push (a) -> | |
| console.log k, v | |
| return k | |
| return k if k is 2 |
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
| var fns, k, v, __fn, __result; | |
| var __return={}, __break={}; | |
| fns = []; | |
| __fn = function(arguments, k, v) { | |
| if (k === 0) return; | |
| if (k === 1) return [__break]; | |
| fns.push(function(a) { | |
| console.log(k, v); | |
| return k; | |
| }); | |
| if (k === 2) return [__return, k]; | |
| }; | |
| for (k in obj) { | |
| __result = __fn.call(this, arguments, k, obj[k]); | |
| if(!__result) continue; | |
| if(__result[0] === __return) return __result[1]; | |
| if(__result[0] === __break) break; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment