The following JS:
(function() {
"use strict";
$("#target").click(function(){
console.log("clicked");
});
}());
继承:
test.js: line 5, col 3, $ is not defined.
当使用JHint0.5.5时。 任何想法?
The following JS:
(function() {
"use strict";
$("#target").click(function(){
console.log("clicked");
});
}());
继承:
test.js: line 5, col 3, $ is not defined.
当使用JHint0.5.5时。 任何想法?
如果你使用比较近期的JHint版本,通常更可取的做法是在你的项目根基中建立一个jshintrc文档,并将这一简略列入:
{
"globals": {
"$": false
}
}
这向人权联盟宣布,美元是一个全球性的变数,而错误表明,它不应凌驾于一切之上。
最初的Jshintrc案(例如,与2012年原始问题一样)没有得到支持。 如果你不能或不想使用jshintrc文档,你可以在文件顶上添加:
/*globals $:false */
你还可以在你看来增加两条。
"globals": {
"$": false,
"jQuery": false
}
这说明有两种全球变量。
页: 1
http://www.jshint.com/docs/options/#jquery。 JSHint Options reference:
jquery
这一办法界定了Jan Query Java成文图书馆所揭露的全球人物。
Here is a happy little list to put in your .jshintrc
I will add to this list at time passes.
{
// other settings...
// ENVIRONMENTS
// "browser": true, // Is in most configs by default
"node": true,
// others (e.g. yui, mootools, rhino, worker, etc.)
"globals": {
"$":false,
"jquery":false,
"angular":false
// other explicit global names to exclude
},
}
如果您重新使用英特尔利J编辑,如WebStorm、PyCharm、Ruby Mine或IntelliJ IDEA:
In the Environments section of File/Settings/JavaScript/Code Quality Tools/JSHint, click on the jQuery checkbox.
我建议使用Module patterns来解决这个问题。 它保留了你的代码“包含”并提高了业绩(基于Paul Irish s 10 。
我倾向于撰写我的模块模式,如:
(function (window) {
// Handle dependencies
var angular = window.angular,
$ = window.$,
document = window.document;
// Your application s code
}(window))
您可以领取这些其他业绩福利(详情见http://briancray.com/posts/javascript-module-pattern”rel=“nofollow”>here):
window
object declaration gets minified as well. e.g. window.alert()
become m.alert()
.window
object.window
property or method, preventing expensive traversal of the scope chain e.g. window.alert()
(faster) versus alert()
(slower) performance.如果你重新使用英特尔利J编辑,主编
你可以做任何事情,例如<代码>console:false,并将在清单(jshintrc)中加上全球。
在使用:
您也许想做以下工作:
const $ = window.$
避免出现倾斜错误。
How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.
I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...
I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...
Is it possible for someone to give me a few pointers on how to display a multidimensional array in the form of a bar graph? The array is multidimensional, with three elements in each part - and the ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.