Skip to content

Instantly share code, notes, and snippets.

@kotaroito
Created July 25, 2014 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kotaroito/9ec4776e0924f8fd6efa to your computer and use it in GitHub Desktop.
Save kotaroito/9ec4776e0924f8fd6efa to your computer and use it in GitHub Desktop.
var Leaker = function() {};
Leaker.prototype = {
init: function(name){
this._interval = null;
this.start();
this.name = name;
},
start: function() {
var self = this;
this._interval = setInterval(function() {
self.onInterval();
}, 100);
},
destroy: function() {
if (this._interval !== null) {
clearInterval(this._interval);
}
},
onInterval: function() {
console.log("Interval: " + this.name);
}
};
var leak;
document.getElementById('start_button').addEventListener('click', function() {
if (leak !== undefined) {
return;
}
leak = new Leaker();
leak.init('test');
}, false);
document.getElementById('destroy_button').addEventListener('click', function() {
leak = null;
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment