api mapping

memolus at googlemail.com memolus at googlemail.com
Fri Dec 25 04:16:45 PST 2009

Hello. I want to map
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

More information about the es-discuss mailing list