0

我对 jQuery .filter() 函数有一个小问题

这种构造不起作用(我得到一组空元素):

jQuery( selector )
.filter( function() {
    return
        long_condition_1 &&
        long_condition_2 &&
        ...
        long_condition_N
} );

这个结构对我有用:

jQuery( selector )
.filter( function() {
    return long_condition_1 &&
        long_condition_2 &&
        ...
        long_condition_N
} );

为什么需要在return关键字后设置空格字符?

我使用 npp 代码编辑器。我试图设置UNIX-format行尾和WIN-format- 两者的结果相同。

4

1 回答 1

1

您的第一个return被解释为return ;这是因为ASI自动分号插入:

7.9.1 分号自动插入规则

分号插入的三个基本规则:

  1. 当从左到右解析程序时,遇到任何语法生成都不允许的标记(称为违规标记)时,如果出现以下一项或多项,则在违规标记之前自动插入分号条件为真:
    • 有问题的令牌与前一个令牌至少分开一个LineTerminator
    • 有问题的令牌是}.
  2. 当程序从左到右解析时,遇到输入令牌流的末尾,并且解析器无法将输入令牌流解析为单个完整的 ECMAScript Program,则在末尾自动插入分号输入流。
  3. 当程序从左到右解析时,遇到某个语法产生式允许的记号,但产生式是受限制的产生式,并且该记号将是紧跟注释之后的终端或非终端的第一个记号“ [no LineTerminatorhere] ”在受限产生式中(因此这样的记号被称为受限记号),并且受限记号与前一个记号至少有一个LineTerminator分隔,然后在受限记号之前自动插入分号。

However, there is an additional overriding condition on the preceding rules: a semicolon is never inserted automatically if the semicolon would then be parsed as an empty statement or if that semicolon would become one of the two semicolons in the header of a for statement (see 12.6.3).

于 2013-10-21T02:06:54.150 回答