This snippet is what I found in the book [Javascript – the good parts]
It simply did not work. Missing ‘}’ in the “var myObject…” line as IE8 described an error.
Anything that I missed?
// Create myObject. It has a value and an increment
// method. The increment method takes an optional
// parameter. If the argument is not a number, then 1
// is used as the default.
var myObject = {
value: 0;
increment: function (inc) {
this.value += typeof inc === 'number' ? inc : 1;
}
};
myObject.increment( );
document.writeln(myObject.value); // 1
myObject.increment(2);
document.writeln(myObject.value); // 3
In object literals, properties are separated by commas (
,), not semicolons (;). Change this:to this: