use strict 小坑
use strict的小坑有点没听懂,什么abc可以?where 不可以?
use strict的小坑有点没听懂,什么abc可以?where 不可以?
2015-01-20
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");
}();举报