简体   繁体   English

“myFunction”已定义但从未使用过&缺少“use strict”语句冲突

[英]“myFunction” is defined but never used & Missing “use strict” statement clash

I was using JavaScript Code in my index.html page. 我在index.html页面中使用了JavaScript代码。 and then I thought to shift all my JavaScript code to .js file. 然后我想把我所有的JavaScript代码转移到.js文件。 so when I did all the copy-paste thing and moved all my code to .js file. 所以,当我完成所有复制粘贴的事情并将我的所有代码移动到.js文件。 I started getting error in Dreamweaver 我开始在Dreamweaver中收到错误

error was: Missing "use strict" statement 错误是:缺少“使用严格”声明

and so I wrote "use strict"; 所以我写了"use strict"; on top of my .js file 在我的.js文件之上

now I started getting error : Use the function form of "use strict" 现在我开始收到错误:使用“use strict”的函数形式

so I tried (function () { "use strict"; //rest of my code })(); 所以我试过(function () { "use strict"; //rest of my code })();

now I have solved all the error related to "use strict"; 现在我已经解决了与"use strict";相关的所有错误"use strict";

but now I have another error : "myFunction" is defined but never used. 但现在我有另一个错误:“myFunction”已定义但从未使用过。

and to solve that I'm using /*exported myFunction*/ 并解决我正在使用/*exported myFunction*/

but that is not working can anyone guide what should I do to remove 2 error I'm getting ? 但这是行不通的任何人都可以指导我应该怎么做才能删除我得到的2个错误?

  1. "myFunction" is defined but never used “myFunction”已定义但从未使用过
  2. Missing "use strict" statement 缺少“使用严格”声明

should I use "use strict"; 我应该使用"use strict"; and /*exported myFunction*/ inside each function of my code onebyone ? /*exported myFunction*/在我的代码onebyone的每个函数内?

Neither of those are errors. 这些都不是错误。 They are warnings that Dreamweaver is alerting you to. 它们是Dreamweaver警告您的警告。

  1. "use strict" is never required, but can be a good best-practice to use in many cases because it can alert you to problems in your code that will silently fail without it. "use strict"从来都不是必需的,但在很多情况下都可以成为一种很好的最佳实践,因为它可以提醒你代码中的问题,如果没有它就会无声地失败。
  2. The fact that you have a function, but never call it is also not an error. 你有一个功能但从不调用它的事实也不是一个错误。 It's just Dreamweaver telling you about code that seems unnecessary because you are not using that code. 它只是Dreamweaver告诉你代码似乎没有必要,因为你没有使用该代码。

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

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