1

我有这个 javascript:

(function ($) {
    // a comment
})(window.jQuery);

我正在使用以下选项运行JSHintwsh 版本:

命令:

%systemroot%\system32\cscript.exe

论据:

//Nologo "%userprofile%\Documents\jshint\env\wsh.js" /forin:true,noarg:true,noempty:true,eqeqeq:true,bitwise:true,undef:true,unused:true,browser:true,jquery:true,indent:4,maxerr:500 $(ItemPath)

$(ItemPath)替换为 Visual Studio 中的当前选定项)

...它给了我这个输出:

[%pathname%\js\JScript1.js]
Line 3 character 18: Object doesn't support this property or method

Implied globals:
    window: 3

我尝试将括号安排为使用JSLint样式,但这给了我同样的错误:

(function ($) {
    // a comment
}(window.jQuery));

我的 javascript 做错了什么还是 JSHint 错误?

更新:我倾向于 JSHint 错误,这个 javascript:

(function ($) {
    // a comment
})(window.jQuery);
// is this a bug?
window.alert("maybe?");

给我这个错误:

Line 5 character 23: Object doesn't support this property or method

更新#2:我认为这是将 args 传递给的正确方法wsh.js

//U //Nologo "%userprofile%\Documents\jshint\env\wsh.js" /forin:true /noarg:true /noempty:true /eqeqeq:true /bitwise:true /undef:true /unused:true /browser:true /jquery:true /indent:4 /maxerr:500 $(ItemPath)

但是,这段代码:

(function (w, $) {})(window, jQuery);

仍然输出:

[%pathname%\js\JScript1.js]
Line 1 character 37: Object doesn't support this property or method

更新#3:事实证明,我确实是个白痴。

我试图使用最新的: https ://nodeload.github.com/jshint/jshint/zipball/master

...当我应该使用r09时: https ://nodeload.github.com/jshint/jshint/zipball/r09

4

2 回答 2

1

所以这是最新主控中的一个错误,它已在 r10 版本中修复:http: //www.jshint.com/changelog/

于 2012-08-22T18:05:41.393 回答
-1

您不想window.jQuery通过自实例化匿名函数作为参数传递,而是window, jQuery. Objectwindow没有方法jQuery,因此出现错误。

于 2012-08-16T16:21:10.940 回答