-
-
Save pvdz/5652207 to your computer and use it in GitHub Desktop.
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
| // original: https://gist.github.com/qfox/5652198 | |
| // this rewrite tries to use globals for any local vars | |
| // you'll have the burden of extra scopes, but it beats dynamic vars (https://gist.github.com/qfox/5652201) | |
| // step1: change var | |
| var $start_foo; | |
| function start(x){ | |
| $start_foo = 0; | |
| if (x === 1) $start_foo = 1; | |
| else if (x === 2) $start_foo = 2; | |
| else if (x === 3) $start_foo = 3; | |
| else if (x === 4) $start_foo = 4; | |
| else $start_foo = 5; | |
| return $start_foo; | |
| } | |
| // step2: split up code branches | |
| var $start_foo = {}; | |
| function start(x){ | |
| $start_foo = 0; | |
| if (x === 1) $start_foo = 1; | |
| else $start1(x); | |
| return $start_foo; | |
| } | |
| function $start1(x){ | |
| if (x === 2) $start_foo = 2; | |
| else $start2(x); | |
| } | |
| function $start2(x){ | |
| if (x === 3) $start_foo = 3; | |
| else $start3(x); | |
| } | |
| function $start3(x){ | |
| if (x === 4) $start_foo = 4; | |
| else $start_foo = 5; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment