jQuery.inArray Easy Improvement
Since probably somebody left the Dynamic post where it is, I would like to open this new discussion about jQuery.inArray, which is basically an indexOf and which is not optimized.
I simply quote myself to make things clear, Regards.
----------------------------------------------------------------------------------
Just a curiosity, are you using indexOf with jQuery instances as well?
In this case line 411 of core.js
<span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;">inArray: Array.prototype.indexOf ?</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (function( indexOf ) {</span><br style="font-family: courier new,monospace;"><div class="im"><span style="font-family: courier new,monospace;"> return function( elem, array ) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> return indexOf.call( array, elem );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
</div><span style="font-family: courier new,monospace;"> })( Array.prototype.indexOf ) :</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> function( elem, array ) {</span><div class="im">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> for ( var i = 0, length = array.length; i < length; i++ ) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if ( array[ i ] === elem ) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> return i;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return -1;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"></div><span style="font-family: courier new,monospace;"> ,</span>
otherwise if this function supposes to work only with array (due to explicit name) just this:
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> inArray: Array.prototype.indexOf ?</span><br style="font-family: courier new,monospace;"><div class="im"><span style="font-family: courier new,monospace;"> function( elem, array ) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> return array.indexOf( elem );</span><br style="font-family: courier new,monospace;"></div><span style="font-family: courier new,monospace;"> } :</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> function( elem, array ) {</span><br style="font-family: courier new,monospace;"><div class="im"><span style="font-family: courier new,monospace;"> for ( var i = 0, length = array.length; i < length; i++ ) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> if ( array[ i ] === elem ) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return i;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> return -1;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
</div><span style="font-family: courier new,monospace;"> ,</span>
I am sure they'll follow this logic so I would not worry about trunk.