Created
June 27, 2011 09:46
-
-
Save victusfate/1048590 to your computer and use it in GitHub Desktop.
working CoffeeScript class member bind
This file contains 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
class GameOfLife | |
#rest of class omitted | |
#see http://github.com/victusfate/life | |
update: (playpause=1) -> | |
#jk dual flip flop flashback | |
if playpause == @playpause | |
@playpause = 0 | |
clearTimeout @time_out_id if @time_out_id | |
else | |
@playpause = 1 | |
# guts of method omitted | |
if @playpause > 0 | |
@time_out_id = setTimeout( => | |
@update(2) | |
500) | |
return | |
window.GameOfLife = GameOfLife |
This file contains 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 GameOfLife; | |
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | |
GameOfLife = (function() { | |
function GameOfLife() {} | |
GameOfLife.prototype.update = function(playpause) { | |
if (playpause == null) { | |
playpause = 1; | |
} | |
if (playpause === this.playpause) { | |
this.playpause = 0; | |
if (this.time_out_id ) { | |
clearTimeout(this.time_out_id); | |
} | |
} else { | |
this.playpause = 1; | |
} | |
if (this.playpause > 0) { | |
this.time_out_id = setTimeout(__bind(function() { | |
this.update(2); | |
return 500; | |
}, this)); | |
} | |
}; | |
return GameOfLife; | |
})(); | |
window.GameOfLife = GameOfLife; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment