據this articleJavaScript中的「嚴格使用」不起作用?
Adding 「use strict」 as the first statement¹ in your JavaScript code will enforce Strict Mode over the entire
那麼爲什麼:
"use strict";
012;
不會引發錯誤
而
(function() {
"use strict";
012; })();
呢? (八進制文字不是在嚴格模式允許的。)
John resig says nothing about it. he just says :
Simple. Toss this at the top of a program to enable it for the whole script:
"use strict"; Or place it within a function to turn on strict mode only within that context.
function imStrict(){ "use strict"; // ... your code ... }
編輯:
編輯#2。
我在控制檯中測試了代碼(chrome)。在jsbin示例中 - 它正在工作。仍然,我不明白爲什麼它在控制檯中表現不同。
如果你用'strict strict'會發生什麼; 012;'在一行? – melpomene
@melpomene相同。剛剛測試過。 –
那麼,無論你使用的是什麼,REPL都不支持頂級的「use strict」。 – melpomene