api mapping
David-Sarah Hopwood
david-sarah at jacaranda.org
Fri Dec 25 07:56:57 PST 2009
memolus at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 292 bytes
Desc: OpenPGP digital signature
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20091225/0aa9baad/attachment.bin>
More information about the es-discuss
mailing list