0
<!DOCTYPE html>
<html>
<body>
<script>
function useStrict(){
"use strict";
}
"use strict";
foo=10;
alert(foo);
</script>
</body>
</html>
导致没有错误。结论:严格模式未被激活。但是,如果我删除了功能定义:结合“严格使用”会发生什么;内部功能与“严格使用”;在全球范围内?
<!DOCTYPE html>
<html>
<body>
<script>
"use strict";
foo=10;
alert(foo);
</script>
</body>
</html>
我收到一个错误。结论:严格模式被激活。但是,如果我删除"use strict"
线在全球范围内,并保持功能:
<!DOCTYPE html>
<html>
<body>
<script>
function useStrict(){
"use strict";
}
foo=10;
alert(foo);
</script>
</body>
</html>
我没有得到任何错误。结论:严格模式未被激活。这里发生了什么?
看来,当"use strict";
既在全局上下文中,又在函数中时,它们将抵消,因为当我删除函数时,严格模式确实被激活。但是,没有"use strict";
行在全局范围内,但在函数里面,严格模式没有被激活,这对我来说是意想不到的。如果函数调用内部的"use strict";
本身没有激活严格模式,他们怎么能在之前取消?
''严格使用''''表达式必须是'