Javascript方法调用模式示例不起作用,为什么?
这段代码就是我在书中发现的[Javascript-好的部分] 它根本不起作用。“var myObject…”行中缺少“}”,因为IE8描述了一个错误 我错过了什么Javascript方法调用模式示例不起作用,为什么?,javascript,Javascript,这段代码就是我在书中发现的[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 a
// 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
在中,属性由逗号(,
)分隔,而不是分号(;
)。更改此项:
value: 0;
为此:
value: 0,
在中,属性由逗号(,
)分隔,而不是分号(;
)。更改此项:
value: 0;
为此:
value: 0,
出于好奇,你为什么要使用IE8而不是一个能为你提供有用开发工具的浏览器?我缺乏经验。很好的提示。即使是Firefox 3.6(2010年1月推出)+Firebug在开发工具方面也远远领先于IE8。出于好奇,你为什么要使用IE8而不是提供有用开发工具的浏览器?我缺乏经验。好提示。即使是Firefox3.6(2010年1月推出)+Firebug在开发工具方面也远远领先于IE8。