【发布时间】:2015-11-03 11:47:48
【问题描述】:
我有一个简单的代码:
_create: function () {
var self = this;
$("#Grid").on("click", ".Row", function () {
$(self).hasClass('Expanded') && $('html, body').animate({
scrollTop: $(self).offset().top
}, 500);
});
},
在 Jslint 上出现以下错误:
期待一个赋值或函数调用,但看到一个表达式 },500)
我认为它可能会因为&& 调用而引发此错误,但我更愿意保持这种方式。
解决这个问题的最佳方法是什么?
【问题讨论】:
-
为什么不能这样写?
if($(self).hasClass('Expanded')){ //that animation code here } -
hasClass使用的返回布尔值的函数不与函数调用一起使用 -
@Rajaprabhu Aravindasamy 因为代码与一堆其他 js 捆绑在一起并被编译为 min.js 文件,这使得代码具有这种形式
-
&& 仅在 if/else if 条件下才有意义。例如
if(cond1 && cond2){...}