如何在Chrome开发者工具的控制台中启用下划线? [英] How to enable to use underscore in console in Chrome developer tool?
问题描述
我正在使用Angular2和下划线,
I'm using Angular2 and underscore,
import * as _ from 'underscore';
,我也想在Chrome控制台窗口中使用下划线库. 甚至我确实中断了代码的中间部分,并尝试使用,但是却收到"未定义"错误.
and I want to use the underscore library in Chrome console window too. Even I do break on a middle of the code, and try to use , but I got ' is not defined' error.
是否可以在Chrome控制台窗口中使用下划线?怎么样?
Is it possible I can use the underscore in Chrome console window? how?
推荐答案
您只需在页面顶部添加 underscore.js 脚本即可完成此操作:
You can simply do it by adding underscore.js script onto the head of your page:
1)转到要调试页面的 Chrome控制台.
1) Go to Chrome Console of the page you wish to debug.
2)运行此脚本以导入 underscorejs ,以便控制台开始识别_
命令:
2) Run this script to import underscorejs so that the console starts recognizing _
commands:
var s = document.createElement('script');
s.type = 'text/javascript';
s.src = 'https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js';
document.head.appendChild(s);
或者,您可以将这样的 import脚本代码保存在片段中,以备将来使用:
Alternatively, you can save such import script code inside a snippet for further usage:
转到源标签,选择代码段子选项卡,单击+
添加新的代码段,然后添加以下代码并保存:
Go to source tab, select snippet sub-tab, click on +
to add a new snippet, then add the following code and save:
(function () {
if (typeof window._ === 'undefined') {
var s = document.createElement('script');
s.type = 'text/javascript';
s.src = 'https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js';
document.head.appendChild(s);
}
}());
这样,每当需要使用外部库调试页面时,只需运行对应的代码段即可添加页面!
This way, whenever you need to debug a page using an external library, you can simply add it by running its correspondent snippet!
这篇关于如何在Chrome开发者工具的控制台中启用下划线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!