Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Created December 18, 2012 19:23
Show Gist options
  • Select an option

  • Save WebReflection/4331070 to your computer and use it in GitHub Desktop.

Select an option

Save WebReflection/4331070 to your computer and use it in GitHub Desktop.
another example of yield possibilities
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