简体   繁体   English

为什么严格模式的激活器'使用严格'字符串?

[英]Why is strict mode's activator 'use strict' a string?

Not to be confused with wanting to know how use strict works, but why is strict mode activated with 'use strict'; 不要混淆想知道如何使用严格的工作,但为什么严格模式激活'use strict'; or "use strict"; "use strict"; as opposed to an expression like use strict; 而不是像use strict;的表达use strict; ?

use strict; would throw an error in JS engines that did not support strict mode. 会在不支持严格模式的JS引擎中抛出错误。

Using a string is backwards compatible. 使用字符串是向后兼容的。

I think the answer is simple. 我认为答案很简单。 As we know, ECMAScript aka javascript is not standarized until now. 众所周知,ECMAScript又称javascript直到现在还没有标准化。 So why string? 串为什么呢? It's because all browsers agree to use 'use strict' as more preferable than use strict . 这是因为所有浏览器都同意使用'use strict'use strict更优先。 It also to prevent error on older browser which is not support strict mode. 它还可以防止不支持严格模式的旧浏览器出错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM