Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properties support #15

Open
QuentinRoy opened this issue May 26, 2014 · 2 comments
Open

Properties support #15

QuentinRoy opened this issue May 26, 2014 · 2 comments

Comments

@QuentinRoy
Copy link

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

@krisk
Copy link
Contributor

krisk commented Jun 23, 2014

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

@QuentinRoy
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants