したがって、「CHILD」を事前にフィルタリングする関数は次のとおりです。
function(match){
if ( match[1] === "nth" ) {
// parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" ||
!/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
// calculate the numbers (first)n+(last) including if they are negative
match[2] = (test[1] + (test[2] || 1)) - 0;
match[3] = test[3] - 0;
}
// TODO: Move to normal caching system
match[0] = done++;
return match;
}
コードはsizzle.js の 442 ~ 458 行から抽出されます。
では、なぜこの行var test = ...
は、exec にブール値を入力させているのでしょうか? それとも本当に文字列ですか?
誰かがそれをさらに数行のコードに分割して説明できますか?