Вопрос

I have a small problem with jQuery .filter() function

This construction does not work (I get an empty set of elements):

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

And this construction works for me:

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

Why is there a need to set a space character after return keyword?

I use npp code editor. I tried to set UNIX-format for line endings and WIN-format - same result for both.

Это было полезно?

Решение

Your first return is interpreted as return ; that's because of the ASI the Automatic Semicolon Insertion:

7.9.1 Rules of Automatic Semicolon Insertion

There are three basic rules of semicolon insertion:

  1. When, as the program is parsed from left to right, a token (called the offending token) is encountered that is not allowed by any production of the grammar, then a semicolon is automatically inserted before the offending token if one or more of the following conditions is true:
    • The offending token is separated from the previous token by at least one LineTerminator.
    • The offending token is }.
  2. When, as the program is parsed from left to right, the end of the input stream of tokens is encountered and the parser is unable to parse the input token stream as a single complete ECMAScript Program, then a semicolon is automatically inserted at the end of the input stream.
  3. When, as the program is parsed from left to right, a token is encountered that is allowed by some production of the grammar, but the production is a restricted production and the token would be the first token for a terminal or nonterminal immediately following the annotation "[no LineTerminator here]" within the restricted production (and therefore such a token is called a restricted token), and the restricted token is separated from the previous token by at least one LineTerminator, then a semicolon is automatically inserted before the restricted token.

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).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top