0

このスニペットは、私が本[Javascript-良い部分]で見つけたものです。

それは単に機能しませんでした。IE8がエラーを記述したため、「varmyObject...」行に「}」がありません。

私が逃したものはありますか?

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

1 に答える 1

4

オブジェクトリテラルでは、プロパティは,セミコロン()ではなくコンマ()で区切られます;。これを変える:

value: 0;

これに:

value: 0,
于 2013-01-24T03:34:11.313 に答える