public
Last active

working CoffeeScript class member bind

  • Download Gist
working_member_bind.coffee
CoffeeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
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
working_member_bind.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
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;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.