我需要如何修改这些行才能让jshint满意?
赋值是一个表达式。为什么jshint不理解这一点呢?显然,解释器是这样做的。
Line 572: while(bookmark_element=bookmark_list[iterator++])
Expected a conditional expression and instead saw an assignment.
Line 582: while(bookmark_element=bookmark_list[iterator++])
Expected a conditional expression and instead saw an assignment.
Line 623: while(element_iterator=element_iterator.nextSibling)
Expected a conditional expression and instead saw an assignment.
发布于 2011-11-13 06:59:26
如果您确实想要侦听JSHint,请通过以下方式将表达式转换为布尔值:
while (!!(bookmark_element=bookmark_list[iterator++]))
! means: Something that evaluates to true is converted to false,
something that evaluates to false is converted to true.
因此,!!
的意思是:将某些东西转换为条件表示。
发布于 2011-11-13 06:57:49
/*jshint boss:true */
使用options进行实验。
发布于 2011-11-13 06:57:49
我确信jshint很好地理解了这个表达式,只是大多数编写if (a = b)
的人实际上是指if (a == b)
,所以这会生成一个警告。
因为你的代码是你想要的,所以你可以添加一个显式的测试:
while ((element_iterator = element_iterator.nextSibling) !== null) { ... }
https://stackoverflow.com/questions/8108184
复制相似问题