Created
December 18, 2012 19:23
-
-
Save WebReflection/4331070 to your computer and use it in GitHub Desktop.
another example of yield possibilities
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 loop = coroutine(function loop(e) { | |
| // could be outer scope moving variable too | |
| // so that woul dbe shared within generators | |
| loop.moving = 0; | |
| while (yield e) { | |
| if (e.type == 'mousedown') { | |
| loop.moving++; | |
| while (e = yield) { | |
| if (e.type == 'mousemove') | |
| move(e); | |
| if (e.type == 'mouseup') { | |
| loop.moving--; | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| $('#box1').mousedown(loop); | |
| $('#box2').mousedown(loop); | |
| $(window).mousemove(loop) | |
| .mouseup(loop); | |
| // whenever is needed | |
| loop.moving; // 1, 2, ... more ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment