JSHint 错误“对象不支持此属性或方法”用于 javascript 闭包
JSHint error "Object doesn't support this property or method" for javascript closures
我有这个javascript:
(function ($) {
// a comment
})(window.jQuery);
我正在使用以下选项运行 JSHint 的 wsh 版本:
命令:
%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:我认为这是将参数传递给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
所以这是最新 master 中的一个错误,并且已在 r10 版本中修复:http://www.jshint.com/changelog/
您不希望通过自实例化匿名函数将window.jQuery
作为参数传递,而是window, jQuery
。对象window
没有方法jQuery
,因此错误。
相关文章:
- 用于检查数组中是否存在元素的javascript自定义方法
- 让会话值可用于JavaScript的好方法是什么
- 如何将原型用于自定义方法和对象操作
- 锚定标签点击方法不适用于互联网探索11
- 用于数组原型的JavaScript独特方法
- JSHint 错误“对象不支持此属性或方法”用于 javascript 闭包
- jQuery .change() 方法不适用于动态创建的复选框
- 需要减少用于获取日期格式的javascript方法代码
- 是否有任何方法适用于“WebGLRenderingContext”,如“CanvasRenderingContext2D
- 组合用于隐藏或显示内容的方法
- Javascript CharAt 方法不适用于字符串
- 将$ionicLoading.show()用于外部链接的方法
- JQuery.on(“mouseover”)方法不适用于IE
- 将带有方法的对象转换为Javascript中的字符串(用于Photoshop)
- 如何将 hasNext() 和 hasPrevious() 方法用于 Node 的“智能列表”链表模块
- 当 prompt() 方法用于初始化 javascript 中的变量时,初始化变量的类型是什么
- 为什么 jQuery 包中没有 $.ajax 方法用于 node.js
- 可搜索的加密方法(用于伪加密!)
- getDate()方法用于倒计时计时器
- 方法用于大多数高性能虚线矩形