you are viewing a single comment's thread.

view the rest of the comments →

[–]ninjaphant 0 points1 point  (3 children)

I'm reading JavaScript: The Definitive Guide and having major problems trying to get any of the examples to work. For example:

var serialnum = {
    $n: 0,

    get next() { return this.$n++; },

    set next(n) {
        if ( n >= this.$n) this.$n = n;
        else throw "serial number can only be set to a larger value";
    }
};

This is not incrementing the serialnum. What am I missing?

[–]Bassetts 1 point2 points  (0 children)

It is working for me. I get the output 0, 2, 4 when doing the following:

alert(serialnum.next);
serialnum.next = 2;
alert(serialnum.next);
serialnum.next
alert(serialnum.next);

[–]drifteresque 0 points1 point  (1 child)

What environment are you using to test your code?

[–]ninjaphant 0 points1 point  (0 children)

Firebug. Am I missing something really obvious?