Heres my first attempt:
It works great, but Im weary of the CPU setIntervals can consume.
Code:
Object.prototype.addProperty = function($prop, $getter, $setter) {
this[$prop] = "";
this.getter = $getter;
this.setter = $setter;
var _this = this;
this.listener = setInterval(function() {
if(_this[$prop] != _this.getter()) {
_this.setter(_this[$prop]);
_this[$prop] = _this.getter()
}
},30)
}
Code:
Useage ::
// Object.addProperty(property:String, getter:Function, setter:Function);
myDiv.addProperty("_x",function() { return this.style.left; }, function(x) { this.style.left = x+'px';});
This could be a perfect solution without the setInterval. Any ideas?
Bookmarks