likes
comments
collection
share

严格模式-use strict

作者站长头像
站长
· 阅读数 30

变量使用前必须声明:

严格模式-use strict严格模式-use strict

不能直接对变量操作delete:

严格模式-use strict严格模式-use strict

静默失败转为异常

常见的静默失败:

  • 给对象不可写属性赋值
  • 给对象只读属性赋值
  • 给不可扩展对象的新属性赋值
  • 删除对象中不可删除的属性

严格模式-use strict严格模式-use strict

函数-参数是唯一

严格模式-use strict

严格模式-use strict

函数-实参和形参的映射关系不存在

严格模式-use strict

严格模式-use strict

形参有默认值时,默认开启严格模式,即实参和形参的映射关系不存在:a里面的值是实参,arguments是形参严格模式-use strict

不允许使用eval()、with()

eval():将字符串解析为js语句为什么不让用了,因为大强大了,会引起一些安全漏洞严格模式-use strict

严格模式-use strict

with():改变函数执行时的上下文严格模式-use strict

严格模式-use strict

eval、arguments不能作为标识符

严格模式-use strict

严格模式-use strict

函数的默认this指向变为undefined

严格模式-use strict

严格模式-use strict

不允许出现八进制数

0b开头是二进制,0开头是八进制,0x开头是十六进制因为0开头会有歧义,有可能是补位严格模式-use strict

严格模式-use strict

不能使用caller和arguments.callee

严格模式-use strict

严格模式-use strict

严格模式-use strict

严格模式-use strict

callee使用场景:匿名函数中需要调用本身、递归等功能:严格模式-use strict

代替方案:给匿名函数命名严格模式-use strict

转载自:https://segmentfault.com/a/1190000042228389
评论
请登录