使用Function.toString对JavaScript问题进行故障排除

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!

太棒了 现在,我可以一目了然地看到功能代码,可以更轻松地浏览可能导致问题的原因并查看需要更改的内容。 通常,您可以找到问题所在的任何提示都会有很大帮助!

翻译自: https://davidwalsh.name/function-tostring

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值