HTML:
<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” href=”https://www.home1024.com/article/resources/css/ext-all.css” />
<script type=”text/javascript” src=”https://www.home1024.com/article/adapter/ext/ext-base.js”></script>
<script type=”text/javascript” src=”https://www.home1024.com/article/ext-all.js”></script>
<script type=”text/javascript” src=”https://www.home1024.com/article/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内容:
Author:binarytree
*/
// 填充图片的本地引用
Ext.BLANK_IMAGE_URL = ‘resources/images/default/s.gif’;
// 命名空间
Ext.namespace(‘myNameSpace’);
// 创建应用程序
myNameSpace.app = function()
{
return
{
init: function()
{
alert(‘程序初始化完毕’);
}
};
}();
网上索引一番,等到如下结果:ECMAScript规定在有些情况下,可以对JavaScript语句执行自动分号补全,return就是其中之一;
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.
我index.js里的第11行处,在JavaScript解析引擎解析的时候自动补全了分号,导致后面的语句不能执行;
解决办法:return后面的大括号不要在新行起用,避免被自动补全分号;
虽然很简单,但对我是今天的新知之一;^__^
以上就是【JavaScript 自动分号插入(JavaScript synat:auto semicolon insertion)】的全部内容了,欢迎留言评论进行交流!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
8. 精力有限,不少源码未能详细测试(解密),不能分辨部分源码是病毒还是误报,所以没有进行任何修改,大家使用前请进行甄别
丞旭猿论坛
暂无评论内容