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

Source: Internet
Author: User

Check the Code:
HTML: Copy codeThe Code is as follows: <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> index </title>
<Link rel = "stylesheet et" href = "resources/css/ext-all.css"/>
<Script type = "text/javascript" src = "adapter/ext/ext-base.js"> </script>
<Script type = "text/javascript" src = "ext-all.js"> </script>
<Script type = "text/javascript" src = "index. js"> </script>
<Script type = "text/javascript">
Ext. onReady (myNameSpace. app. init, myNameSpace. app );
</Script>
</Head>
<Body>
<Div id = "mydiv"> </div>
<P id = "1"> 1 </p>
<P id = "2"> 2 </p>
<P id = "3"> 3 </p>
<P id = "4"> 4 </p>
</Body>
</Html>

Index. js content:Copy codeThe Code is as follows :/*
Author: binarytree
*/
// Fill in the local reference of the image
Ext. BLANK_IMAGE_URL = 'resources/images/default/s.gif ';
// Namespace
Ext. namespace ('mynamespace ');
// Create an application
MyNameSpace. app = function ()
{
Return
{
Init: function ()
{
Alert ('program initialization completed ');
}
};
}();

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. ^__ ^

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.