在javascript中有时会看到有两个!!的用法。我很少用到(本人在js方面是菜鸟),但是在一些开源框架(如jquery)中经常看到。所以参考网上的相关资料总结了一下它的用法。
- grep: function( elems, callback, inv ) {
- var ret = [], retVal;
- inv = !!inv;
- // 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;
- }
<script type="text/javascript">
</script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>