

// Go through the array, only saving the items
// that pass the validator function
for ( var i = 0, length = elems.length; i < length; i++ ) {
retVal = !!callback( elems[ i ], i );
if ( inv !== retVal ) {
ret.push( elems[ i ] );
}
}
return ret;
}
在使用grep函数的时候,如果给出了第三个参数且非null/undefined/0""/等值,则inv为true,否则为false。这样做的目的就是保证inv和retVal的值都只能在true/false中取,而非其它值,为后续判断提供便利。
