I'm definitely late to this thread, but isn't this what the ES5 Proxy object 
is all about? Even the ES5 Object constructor lets you handle non-mapped 
properties. Also, JavaScript 1.8.1 (available since FireFox 3.5) lets you 
define getters and setters for properties - such that assignments (via "=") 
actually pass arguments to an internal setter function.

Without these, you would need to use closures and use an access schema 
within your get/set functions. The caveat with this non-native approach, is 
that developers would need to learn your table schema, or the API for 
defining it (as you have already). If I'm off, then pardon me and continue 
your discussion...

If I'm right, then check out my previous work, GSet, at 
https://github.com/bemson/GSet/. (It was formally called Proxy, until I 
discovered the ES5 Proxy object.) My approach differs from yours, in that my 
object is compiled (i.e., cannot be changed). XJSAccessors.js lets the 
developer change the access scheme of an object dynamically. Thus, I use a 
configuration object, while you have an API. On the subject of what to name 
getters and setters, I chose to follow jQuery's same-name approach.

As an example, here's how you would use GSet to configure getters, setters, 
and "calculators".

/example------------------------------

var mySquare = new GSet(
  {myWidth:4, myLength:2}, // original/protected object
  { // access scheme
    width: ['myWidth', 'number'],
    length: ['myLength', 'number'],
    area: [
      function () {
        return this.myWidth * this.myLength;
      },
      'number',
      function (w, l) {
        if (arguments.length > 1) {
          this.myWidth = w;
          this.myLength = l;
        } else {
          return false;
        }
      }
    ]
  }
);

mySquare.width(2); // true
mySquare.width(); // 2
mySquare,width('foo'); // false
mySquare.area(); // 4
mySquare.area(10,10); // true
mySquare.area(); // 100

------------------------------example/

One last note: I'm phasing out my own use of GSet, as it's numerous closures 
actually degrade performance.

- best,

bemson

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to