这个片段是我在书中找到的 [Javascript - 好的部分]
它根本不起作用。在“var myObject...”行中缺少 '}',因为 IE8 描述了一个错误。
我错过了什么?
// 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