如何启用ECMAScript

如何启用ECMAScript

本文介绍了如何启用ECMAScript“use strict”全球范围内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含数百个JavaScript源文件的项目。我想知道为项目启用严格模式的最佳方法是什么?我了解此操作的后果,我只是在寻找有关部署此功能的建议。在每个文件中放置use strict看起来并不好玩。

I have a project with literally hundreds of JavaScript source files. I am wondering what is the best way to enable the strict mode for the project? I understand the consequences of this action and I am only looking for advice regarding the deployement of this feature. Placing "use strict" in every file does not seem fun.

推荐答案

好吧,我不清楚你的javascript上下文将使用文件,但是说上下文是一个动态的Web应用程序,其中需要时加载各种页面文件,javascript文件,样式表等,然后我只创建一个只有use strict的单个javascript文件在其中。然后,在您的head标签中包含该文件,在所有其他javascript文件之前包含该文件,并确保如果您将javascript文件动态插入到您在use strict.js之后附加的给定Web应用程序的文档的头部中。文件。

Well, I'm not clear on the context your javascript files will be used in, however say the context is a dynamic web application where various page files, javascript files, style sheets, etc, etc, are loaded when needed, then I would just create a single javascript file with only "use strict" within it. Then, include that file in your head tags, preceding all other javascript files and make sure that if you will be inserting javascript files dynamically into the head of the document of a given web application that you append them after your "use strict" .js file.

这样您就不必浏览每个.js文件并单独修改它们。

That way you won't have to go through each of your .js files and modify them individually.

这篇关于如何启用ECMAScript“use strict”全球范围内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 00:09