2

そのため、彼のヘルプサイトには、「関数宣言を含むすべてのステートメントは、セミコロンで正しく終了する必要があります」と記載されています。

しかし、このサンプルコードでは、彼は特にifステートメントをセミコロンで終わらせないように言っています。

では、セミコロンで終了する必要があるものの完全なリストはありますか?私は自分のJavscriptコードを見ていましたが、パッカーに適切な形式であるかどうかわからなかった場合があります。

1)

for( i in cities ) {
    alert( i );
};

2)

var map = {
    city : 'atlanta',
    year : 1987
};

3)

var info_window = new google.maps.InfoWindow( {
    content : content_div,
    zIndex  : INFO_WINDOW_Z
}; );

4)

var options = {
    business : business,
    columns  : [ 'url', 'image_url', 'expiration', 'percent_discount', 'claimed', 'fine_print' ];
};

5)

$( warp_content ).hover( function() {
    $( deal_description ).fadeIn( 'fast' );
};, function() {
    $( deal_description ).fadeOut( 'fast' );
}; );
4

1 に答える 1

2

There are rules, but sometimes they may not be obvious. Essentially, the following statements do not need terminating semicolons:

  • if (...) { }
  • for (...) { }
  • while (...) { } (except in do { } while (...);)
  • function (...) { } (except for examples such as var f = function() { }; where an anonymous function is part of a larger statement)
  • try { } catch (...) { }
  • with (...) { }

Essentially, anywhere { } surrounds a group of statements, that is a block and no terminating semicolon is required.

于 2012-02-10T04:09:21.137 に答える