码迷,mamicode.com
首页 > 编程语言 > 详细

javascript笔记02:严格模式的特定要求

时间:2015-07-07 21:04:33      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

1.严格模式变量必须声明,不然会报错:

<!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>严格模式</title>
</head>

<body>
<script type="text/javascript">
"use strict";
try {
    i = 1;
}catch(err) {
    alert(err);
}
</script>
</body>
</html>

这里i没有使用var修饰,就是没有定义的意思,后抛出"undeclared variable i"错误

 

2.严格模式下,不能删除全局变量函数函数的参数

<!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>严格模式</title>
</head>

<body>
<script type="text/javascript">
"use strict";
var i;
function myfunc() {};
delete i;//语法错误
delete myfunc();//语法错误
function myfunc2(arg) 
{
delete arg;//语法错误

}
</script> 
</body>
</html>

 

javascript笔记02:严格模式的特定要求

标签:

原文地址:http://www.cnblogs.com/hebao0514/p/4628428.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!