在Chrome中查找JavaScript函数定义 [英] Find JavaScript function definition in Chrome
问题描述
Chrome的开发者工具摇滚,但他们似乎没有(我能找到)的一件事是找到JavaScript函数定义的一种方法。这对我来说非常方便,因为我正在开发一个包含许多外部JS文件的站点。当然grep解决了这个问题,但在浏览器中会好得多。我的意思是,浏览器必须知道这一点,为什么不公开呢?我所期望的是:
Chrome's Developer Tools rock, but one thing they don't seem to have (that I could find) is a way to find a JavaScript function's definition. This would be super handy for me because I'm working on a site that includes many external JS files. Sure grep solves this but in the browser would be much better. I mean, the browser has to know this, so why not expose it? What I expected was something like:
- 从页面中选择检查元素,突出显示元素选项卡中的行
- 右键单击该行并选择转到函数定义
- 在脚本选项卡中加载正确的脚本,它将跳转到函数定义
首先,这个功能是否存在而我只是错过了它?
First off, does this functionality exist and I'm just missing it?
如果它没有,我猜这会来自WebKit,但找不到任何东西 Developer Tool功能请求或 WebKit的Bugzilla 。
And if it doesn't, I'm guessing this would come from WebKit, but couldn't find anything for Developer Tool feature requests or WebKit's Bugzilla.
推荐答案
让我们说我们正在寻找名为 foo的函数
:
Lets say we're looking for function named foo
:
- (打开Chrome开发工具),
- Windows:< kbd> ctrl + shift + F ,或macOS:
cmd + optn + F 。这将打开一个用于搜索所有脚本的窗口。 - 选中正则表达式复选框,
- 搜索
foo \ s * = \ * *函数
(搜索foo = function
,这三个标记之间有任意数量的空格), - 按下返回的结果。
- (open Chrome dev-tools),
- Windows: ctrl + shift + F, or macOS: cmd + optn + F. This opens a window for searching across all scripts.
- check "Regular expression" checkbox,
- search for
foo\s*=\s*function
(searches forfoo = function
with any number of spaces between those three tokens), - press on a returned result.
函数定义的另一个变体是 function \ s * foo \s * \(
for function foo(
,这三个令牌之间有任意数量的空格。
Another variant for function definition is function\s*foo\s*\(
for function foo(
with any number of spaces between those three tokens.
这篇关于在Chrome中查找JavaScript函数定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!