Skip to content

Instantly share code, notes, and snippets.

@kicktheken
Last active August 29, 2015 14:05
Show Gist options
  • Save kicktheken/4c3ec28a878cb94bdfa5 to your computer and use it in GitHub Desktop.
Save kicktheken/4c3ec28a878cb94bdfa5 to your computer and use it in GitHub Desktop.
runtime get vs. immediate get
function Class()
{
this._a = 0;
this._max = 0;
}
Object.defineProperty(Class.prototype, 'a', {
get: function() { return this._a; },
set: function(v) {
if (v > this._max) {
v = this._max;
}
this._a = v;
return v;
}
});
var c = new Class();
c._max = 1000;
requestAnimationFrame(run);
function run(ts) {
console.log(c.a+=10,ts);
requestAnimationFrame(run);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment