找到死的JavaScript代码? [英] find dead JavaScript code?
问题描述
我们正在重构遗留的网络应用程序,因此杀死了相当多的JavaScript代码,但我们害怕因为不确定而删除我们认为的死代码。是否有任何工具/技术可以在JavaScript中正确识别死代码?
We are refactoring a legacy web app and as a result are "killing" quite a lot of JavaScript code but we're afraid of deleting what we think is dead code due to not being sure. Is there any tool / technique for positively identifying dead code in JavaScript?
推荐答案
grep 。用它来查找函数调用。假设您有一个名为 dostuff()
的方法。在项目的根目录中使用 grep -rdostuff()* --color
。除非您找到除定义之外的任何内容,否则您可以安全地删除它。
There's grep. Use it to find function calls. Suppose you have a method called dostuff()
. Use grep -r "dostuff()" * --color
on your project's root directory. Unless you find anything other than the definition, you can safely erase it.
ack 也是 grep 的显着替代品。
这篇关于找到死的JavaScript代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!