JavaScript Automatic semicolon Insert (JavaScript synat:auto semicolon insertion) _javascript tips

Source: Internet
Author: User
Look at the code:
Html:
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>index</title>
<link rel= "stylesheet" 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>
<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>

Index.js content:
Copy Code code as follows:

/*
Author:binarytree
*/
Fill a local reference to a picture
Ext.blank_image_url = ' resources/images/default/s.gif ';
Name space
Ext.namespace (' MyNamespace ');
Creating an Application
Mynamespace.app = function ()
{
Return
{
Init:function ()
{
Alert (' Initialization of program completed ');
}
};
}();

Online index, wait until the following results: ECMAScript in some cases, you can perform automatic semicolon completion on JavaScript statements, return is one of them;
Certain ECMAScript statements (empty statement, variable statement, expression statement, Do-while statement, continue STA Tement, break statement, return statement, and throw statement) must is terminated with semicolons. Such semicolons may always appear explicitly in the source text. For convenience, however, such semicolons May is omitted from the source text in certain situations. These situations are described by saying, semicolons are automatically inserted into the source code token stream in T Hose situations.
In the 11th line of my index.js, the JavaScript parsing engine resolves to automatically complete the semicolon, which causes the following statement not to execute;

Workaround: Return the curly braces on the new line, avoid being automatically filled with semicolons;
Although very simple, but for me is one of today's knowledge; ^__^

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.