memo...@googlemail.com wrote:
> Hello. I want to map
>   document.getElementById("title").value
> to
>   gui.title
> in my ecmascript application. So I can use several implementations of
> gui (html, gtk+, xul, qt, etc.)
> But there's no way to reference to this "title", because it's a
> primitive data type, a "String".
> I've tried the following:
>   let title = document.getElementById("title");
>   gui.__defineGetter__("title", function () {return title.value;});
>   gui.__defineSetter__("title", function (x) {title.value = x;return x;});
> But this code looks ugly and isn't abstract programming. So created
> the following helper function:
>   function link(obj, prop, target, tprop) {
>     obj.__defineGetter__(prop, function () {return target[tprop];});
>     obj.__defineSetter__(prop, function (x) {target[tprop] = x;return x;});
>   }
> It can be used this way:
>   let title = document.getElementById("title");
>   link(gui, "title", title, "value");
> I think it would be easier if such a feature would be built-in in
> ecmascript. If you know a better already-possible way, please let me
> know.

<https://mail.mozilla.org/pipermail/es-discuss/2009-February/008875.html>

(You've asked variations on this question three or four times now. I don't
mind repeating myself a few times, but not indefinitely. The feature is
already in ES5 for properties, it will not be added for local variables,
and there is no need for a 'link' convenience function to be standardized
given that it is a 5-liner in terms of Object.defineProperty.)

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to