Fiber icon indicating copy to clipboard operation
Fiber copied to clipboard

Properties support

Open QuentinRoy opened this issue 10 years ago • 2 comments

I guess everything is in the title. I would love to have this.

QuentinRoy avatar May 26 '14 14:05 QuentinRoy

@QuentinRoy, just to avoid confusion, can you be a little specific? Thanks!

krisk avatar Jun 23 '14 19:06 krisk

I was actually talking about the built in getter and setter mechanism (http://ejohn.org/blog/javascript-getters-and-setters/).

For example I would enjoy being able to do stuff like this:

var PropertyTest = Fiber.extend(function () {

    return {

        init: function (stuff) {
            this.stuff = stuff;
        },

        get stuffAnd2() {
            return this.stuff + 2;
        },

        /*
        set stuffAnd2(val) {
            this.stuff = val - 2;
        }
        */

    };

});

var pTest = new PropertyTest(4);

console.log(pTest.stuffAnd2);
// Should returns 6 but returns 'NaN'.
// Instead, the getter is actually called only once, before the initialization,
// and the returned value is copied in the instance instead of the getter.

pTest.stuffAnd2 = 8;
// Should throw an error because the setter is commented (making stuffAnd2 read-only).
// Instead it overwrites stuffAnd2.

pTest.stuff = 0;
console.log(pTest.stuffAnd2);
// Still prints 8 while it should be 2 now.

QuentinRoy avatar Jun 24 '14 08:06 QuentinRoy