JavaScript automatic semicolon insertion (JavaScript synat: auto semicolon insertion)

Source: Internet
Author: User

When reading Extjs Chinese manual today, I wrote four or five lines of sample code. As a result, IE and Firefox failed to report an error.

Check the Code:

HTML:

 

 

1 <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 3 4 <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
5 <title> index </title>
6 <link rel = "stylesheet" href = "resources/css/ext-all.css"/>
7 <script type = "text/javascript" src = "adapter/ext/ext-base.js"> </script>
8 <script type = "text/javascript" src = "ext-all.js"> </script>
9 <script type = "text/javascript" src = "index. js"> </script>
10 <script type = "text/javascript">
11 Ext. onReady (myNameSpace. app. init, myNameSpace. app );
12 </script>
13 14
15 <body>
16 <div id = "mydiv"> </div>
17 <p id = "1"> 1 </p>
18 <p id = "2"> 2 </p>
19 <p id = "3"> 3 </p>
20 <p id = "4"> 4 </p>
21 </body>
22  

Index. js content:

 

 

1 /*
2 Author: binarytree
3 */
4 // fill in the local reference of the image
5 Ext. BLANK_IMAGE_URL = 'resources/images/default/s.gif ';
6 // namespace
7 Ext. namespace ('mynamespace ');
8 // create an application
9 myNameSpace. app = function ()
10 {
11 return
12 {
13 init: function ()
14 {
15 alert ('program initialization completed ');
16}
17 };
18 }();
19

 

The following results are indexed on the Internet: ECMAScript stipulates that in some cases, automatic semicolon completion can be executed for JavaScript statements, and return is one of them;

Certain ECMAScript statements (empty statement, variable statement, expression statement, do-while statement, continue statement, break statement, return statement, and throw statement) must be terminated with semicolons. such semicolons may always appear explicitly in the source text. for convenience, however, such semicolons may be omitted from the source text in certain situations. these situations are described by saying that semicolons are automatically inserted into the source code token stream in those situations.

The 11th line in index. js is automatically supplemented with semicolons during parsing by the JavaScript parsing engine, resulting in the subsequent statements being unable to be executed;

Solution: Do not use the braces after the return statement on the new line to avoid Automatic completion of semicolons;
Although very simple, I am one of the new things today. ^__ ^

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.