rolandoam / ChesterGL

A simple and performant WebGL game library for 2D games
Other
105 stars 16 forks source link

use javascript's accessors #18

Closed rolandoam closed 12 years ago

rolandoam commented 12 years ago

use __defineGetter__/__defineSetter__ instead of (set | get)PropertyName in all the objects.

rolandoam commented 12 years ago

keeping this one out for now

rolandoam commented 12 years ago

re-open this issue

rolandoam commented 12 years ago

not using defineGetter and setter, but using private properties:

var A = function (depth) {
    // private properties
    var a = "the a";
    var b = "the b";

    // public property
    this.depth = depth;

    // define accessor for a
    Object.defineProperty(this, 'a', {
        get: function () { return a; },
        set: function (newA) { a = newA; console.log("in the setter"); }
    });
};
rolandoam commented 12 years ago

I'm delaying this again until I gain a bigger understanding of how to properly implement this. After a quick tests, it seems that I would introduce a big penalty in performance for a not so big gain in API readability:

http://jsperf.com/creation-time-comparison-for-ecma5-accessors

rolandoam commented 12 years ago

closing this again for now