zoukankan      html  css  js  c++  java
  • 什么是 “use strict”? 使用它的好处和坏处是什么?

    严格模式是ES5引入的,更好的将错误检测引入代码的方法。顾名思义,使得JS在更严格的条件下运行。

    变量必须先声明,再使用
    function test(){
      "use strict";
      foo = 'bar';  // Error
    }
     
    不能对变量执行delete操作
    var foo = "test";
    function test(){}
     
    delete foo; // Error
    delete test; // Error
     
    function test2(arg) {
        delete arg; // Error
    }
    对象的属性名不能重复
    { foo: true, foo: false } // Error
     
    禁用eval()
     
    函数的arguments参数
    setTimeout(function later(){
      // do stuff...
      setTimeout( later, 1000 );
    }, 1000 );
     
    禁用with(){}
     
    不能修改arguments
    不能在函数内定义arguments变量
    不能使用arugment.caller和argument.callee。因此如果你要引用匿名函数,需要对匿名函数命名。
    
  • 相关阅读:
    jmeter工具应用1
    django1
    5.自动化测试模型
    4.清除cookie操作
    2.操作浏览器
    3.8种元素定位
    1.介绍与环境安装
    模块
    urllib库
    自动化测试PO模式
  • 原文地址:https://www.cnblogs.com/shih/p/6919004.html
Copyright © 2011-2022 走看看