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。因此如果你要引用匿名函数,需要对匿名函数命名。
    
  • 相关阅读:
    Emacs 使用YASnippet
    odbc备忘
    Emacs 矩形编辑
    ftp by libcurl
    emacsshell
    Emacs cnblogs 代码着色
    Emacs下的Man
    #include ""还是<>
    三种*
    应对Maze勒索攻击的最佳实践分享
  • 原文地址:https://www.cnblogs.com/shih/p/6919004.html
Copyright © 2011-2022 走看看