Skip to content

Instantly share code, notes, and snippets.

@victusfate
Created June 27, 2011 09:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victusfate/1048590 to your computer and use it in GitHub Desktop.
Save victusfate/1048590 to your computer and use it in GitHub Desktop.
working CoffeeScript class member bind
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
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