不支持 with,arguments.callee,function.caller,变量赋值前必须声明,局部 this 必须被赋值(Person.call(null/undefined) 赋值什么就是什么),拒绝重复属性和参数
使用方法:
全局严格模式
局部函数内严格模式 (例如jquery)
// "use strict"; // 执行a函数时直接报错。functiona(){
console.log(arguments.callee);}functionb(){"use strict";a();// 3.0正常
console.log(arguments.callee);// 5.0报错}functionc(){
console.log(arguments.callee);}a();// 3.0正常try{b();}catch(e){
console.log(e);// TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them};a();// 3.0正常c();// 3.0正常
"use strict";// 3.0 & 5.0functiona(b, b){
console.log(b);// 2 & SyntaxError}a(1,2);var c ={
d :4,
d :5}
console.log(c);// 都是 {d: 5}
with的基本用法
debugger;var arr ={
b :2.1}var b =2;functiona(){var b =2.2;with(arr){
console.log(b);// 2.1 // 比AO权限高
console.log(window.b);// 2}}a();
with解决命名空间
var name ="name0";var org ={
dp1 :{
pers1 :{
name :"name1",
say :function(){
console.log(this.name);}},
pers2 :{
name :"name2",
say :function(){
console.log(this.name);}}},
dp2 :{
pers3 :{
name :"name3",
say :function(){
console.log(this.name);}},
pers4 :{
name :"name4",
say :function(){
console.log(this.name);}}}}
org.dp1.pers2.say();// name2with(org.dp1.pers2){
console.log(name);// name2say();// name2}