Sometimes JavaScript bugs can be the most frustrating damn things in the world. That problem is compounded when a JavaScript file is created from multiple files on the server side or you simply aren't familiar with some of the code used in a project (i.e. troubleshooting an issue with a JavaScript framework you aren't familiar with. Sometimes just identifying the code within a function is enough to point you in the correct direction. So to quickly check the code for a given function, I'll type into the console something like:
有时,JavaScript错误可能是世界上最令人沮丧的事情。 当从服务器端的多个文件创建一个JavaScript文件时,或者您只是不熟悉项目中使用的某些代码(例如,对不熟悉JavaScript框架进行故障诊断),这个问题就变得更加复杂。仅仅识别一个函数中的代码就足以指引您正确的方向,因此,为了快速检查给定函数的代码,我将在控制台中键入以下内容:
myProblemFunction.toString();
That would return something like:
那将返回类似:
function myProblemFunction() {
/* bunch of code here */
some.problem().code;
/* bunch of code here */
}
Awesome. Now that I can get the function code at a glance, I can more easily browse through what could be causing the issue and see what needs to be changed. Usually any hint you can get toward finding where the issue resides is a big help!
太棒了 现在,我可以一目了然地看到功能代码,可以更轻松地浏览可能导致问题的原因并查看需要更改的内容。 通常,您可以找到问题所在的任何提示都会有很大帮助!