[email protected] wrote:
> I'd like to see a feature in ECMAScript to link one object to another.
>
> example implementation:
> Object.prototype.link = function (prop, target, tprop) {
> this.__defineGetter__(prop, function () {return target[tprop];});
> this.__defineSetter__(prop, function (x) {target[tprop] = x;return x;});
> }
Your wish has been granted. This can be implemented in ES3.1 as follows:
function link(obj, prop, target, tprop) {
Object.defineProperty(obj, prop,
{get: function() { return target[tprop]; },
set: function(x) { target[tprop] = x; },
enumerable: true
});
}
(Don't add methods to Object.prototype; it's not necessary, and
Object.prototype is a global namespace that is subject to conflicts.)
--
David-Sarah Hopwood ⚥
_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss