This is a test of getter and setter code. I'm pretty sure there's no way to get it to work in IE.
function addGetter(element, property, method) { if(typeof(element.prototype.__defineGetter__) != "undefined") { element.prototype.__defineGetter__(property, method); } else { try { eval("element[prototype][property] getter = method"); } catch(e) { debug("Failed to add getter for " + property + " to " + element); } } } function addSetter(element, property, method) { if(typeof(element.prototype.__defineSetter__) != "undefined") { element.prototype.__defineSetter__(property, method); } else { try { eval("element.prototype[property] setter = method"); } catch(e) { if(typeof(element.watch) != "undefined") { var wrapper = function(value) { arguments.callee.watchedElement.unwatch(arguments.callee.watchedProperty); arguments.callee.setter(value); arguments.callee.watchedElement.watch (arguments.callee.watchedProperty, arguments.callee); return arguments.callee.watchedElement[arguments.callee.watchedProperty]; } wrapper.setter = method; wrapper.watchedProperty = property; wrapper.watchedElement = element; element.watch(property, wrapper); } else { debug("Failed to add setter for " + property + " to " + element); } } } } TestObject = function() {} TestObject.prototype = new Object; var getterMethod = function() { return this.randomVar ? this.randomVar : 5 }; var setterMethod = function(val) { this.randomVar = val * 100 * Math.random() }; addGetter(TestObject, "dynamicVar", getterMethod); addSetter(TestObject, "dynamicVar", setterMethod); var testObject = new TestObject(); debug("Before Assignment: " + testObject.dynamicVar); testObject.dynamicVar = 20; debug("After Assignment: " + testObject.dynamicVar);