zoukankan      html  css  js  c++  java
  • Javascript笔记02:严格模式的特定要求

    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>
  • 相关阅读:
    ios-pch文件的手动添加
    iOS远程消息推送自我整理版
    iOS远程消息推送
    苹果App store 2015最新审核标准公布(2015.3)
    App上线基本流程
    iOS中常用的正则表达式
    如何获取App当前版本号
    添加Appicon的方法
    键盘弹出
    iOS9适配中出现的一些常见问题
  • 原文地址:https://www.cnblogs.com/hebao0514/p/4628428.html
Copyright © 2011-2022 走看看