es5.0严格模式的启动
页面最上面加上
"use strict"
也可以放在函数的里面最顶端(逻辑最顶端)
function demo() {
console.log(arguments.callee);
}
demo(); //可以执行
function test() {
"use strict";
console.log(arguments.callee);
}
test(); //报错
ES5严格模式
<> "use strict"
- 不再兼容es3的一些不规则语法,使用全新的es5规范
- 两种用法:
- 全局严格模式
- 局部函数内严格模式(推荐)
- 就是一行字符串,不会对不兼容严格模式的浏览器产生影响
- 不支持 with , arguments.callee , func.caller 变量赋值前必须声明,局部this必须被赋值
( Person.call(null/undefined) 赋值什么就是什么),拒绝重复属性和参数。
然后了解一下这些不支持的有多么好用
1.with()
简单来说就是让 with ()里面传的变成 你最直接的执行上下文
var name = 'qwe';
var org = {
dp1:{
tzz:{
name:'abc',
age: 20
},
aha:{
name: 'shabi',
age: 123
}
}}
with(org.dp1.tzz){
console.log(name); // abc
}
也就是命名空间的用法
so,为啥不让用了?
因为它可以改变作用域链,作用域链改了系统会消耗大量效率去更改,让程序变得非常慢。
(¦3[▓▓] 晚安