简体   繁体   English

JavaScript中的严格模式适用于他们的框架吗?

[英]Strict Mode in JavaScript works with their frameworks?

I am studying JavaScript and came across the Strict Mode ("use strict"). 我正在研究JavaScript,并遇到了严格模式(“严格使用”)。 I wonder if it works with JavaScript frameworks(like jQuery, Angular.js, etc) if I put this command in a .js file, or if only work with pure JavaScript? 我想知道它是否适用于JavaScript框架(如jQuery,Angular.js等),如果我将此命令放在.js文件中,还是仅适用于纯JavaScript? And It is currently feasible to use it? 而且目前可以使用吗? because it is only supported by the latest versions of some browsers. 因为只有某些浏览器的最新版本才支持。

strict mode is subset of javascript and it written as a string "use strict" so if older browser doesn't support the strict mode then it consider as a simple string and just ignore it and you code work as simple javascript so it is feasible to use. strict mode是javascript的子集,它写为字符串"use strict"因此,如果较旧的浏览器不支持strict mode则它会视为简单字符串,而忽略它,而您将代码编码为简单javascript,因此可行采用。 I could not find strict mode in jQuery source code but I'm not sure about that. 我在jQuery源代码中找不到严格模式,但我不确定。

Strict Mode is a execution mode of javascript, it has nothing to do with libraries like jQuery or angularjs. 严格模式是javascript的执行模式,与jQuery或angularjs之类的库无关。

So yes you can use strict mode in your code even though you are using some javascript libraries. 因此,是的,即使您正在使用某些javascript库,也可以在代码中使用严格模式。 But when you use strict mode make sure that the mode is applied only those code which you have authored, because we won't know whether another persons code is compatible with this mode. 但是,当您使用严格模式时,请确保仅将该模式应用于您编写的那些代码,因为我们不知道其他人的代码是否与此模式兼容。

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

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