> I fail to see what's the point of this syntax. Considering the fact
> that it's still possible to change the value of editor._startLine
> without the setter, how is that better than using regular functions
> like below?

It's just convenient rather than calling the getter/setter in case the
accessed value is non public. Example:

   function Editor()
    {
        var lineNo = 42;

        this.getLineNumber = function () {
            return lineNo;
        };

        this.setLineNumber = function (no) {
            lineNo = no;
        }
    }

    editor = new Editor;

    Object.defineProperty(editor, "lineNumber", {
        get: function () {
            return this.getLineNumber();
        },
        set: function (no) {
            this.setLineNumber(no);
        }
    });

    console.log(editor.getLineNumber());
    console.log(editor.lineNumber);




-- 
Ariya Hidayat, http://ariya.ofilabs.com

-- 
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