严格模式是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。因此如果你要引用匿名函数,需要对匿名函数命名。

相关文章:

  • 2022-01-04
  • 2022-12-23
  • 2022-12-23
  • 2021-05-20
  • 2021-08-02
  • 2021-12-01
  • 2022-12-23
  • 2021-12-20
猜你喜欢
  • 2021-05-17
  • 2022-12-23
  • 2022-01-22
  • 2021-08-07
  • 2022-12-23
相关资源
相似解决方案