On Wed, Sep 2, 2009 at 2:51 PM, David Zhou <[email protected]> wrote:
>
> Isn't this essentially what jQuery does now?
>
Yes and no - there are several "if" with comments for workaround in the
middle of some method.
I meant something more "drastic" like a proper lazy method assignment.
As example, latest core.js, inArray ...
inArray: function( elem, array ) {
if(Array.prototype.indexOf) {
// could be function( elem, array ){return array.indexOf(elem)};
// dunno if this is used with jQuery.fn.init instances as well
jQuery.inArray = (function(indexOf){
return function( elem, array ){
return indexOf.call(array, elem);
};
})(Array.prototype.indexOf);
} else {
jQuery.inArray = function( elem, array ){
for ( var i = 0, length = array.length; i < length; i++ ) {
if ( array[ i ] === elem ) {
return i;
}
};
return -1;
}
};
return jQuery.inArray(elem, array);
},
... you see what I mean? First execution a part inArray will be natively
faster for every browser but IE.
>
> Indeed. Which is why it's a little silly to consider *how* to do it
> without first making sure *why* we're doing it is based on solid data.
And I guess we all agree about this point ...
Regards
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---