use strict的小坑有点没听懂,什么abc可以?where 不可以?
hi, 亲,意思是'use strict';指令并不一定要在第一行出现的,之前也可以有其它指令(字符串)。
但是不允许有其它语句,如变量声明、赋值等。
例如下面例子中:
上面的use strict前面有abc,仍将进入严格模式,下面的不会进入严格模式。
!function() {
'abc';
'use strict';
console.log(this === undefined ? "strict" : "not strict");
}();!function() {
var a;
'use strict';
console.log(this === undefined ? "strict" : "not strict");
}();'user strict'
'use strict'
这里就是use strict可以不出现在第一行,在use strict前可以使用其他的指令,而将use strict往后移,也是没有问题的