When I read the sizzle code today, there is such a section:
// Here we check if the JavaScript engine is using some sort of
// optimization where it does not always call our comparision
// function. If that is the case, discard the hasDuplicate value.
// Thus far that includes Google Chrome.
[0, 0].sort(function() {
baseHasDuplicate = false;
return 0;
});
Then google found this article: "Chrome V8 engine optimization for sort", which is simply copied:
VaR a = 0, B = 0;
[0, 0]. Sort (function (){
A = 1;
Return 0;
});
[0, 1]. Sort (function (){
B = 1;
Return 0;
});
Alert (A = B); // true or false?
The above Code except chrome outputs false, all other browsers are true.
The reason is that Chrome has optimized the array sort method:
Function sort (comparefn ){
VaR custom_compare = (typeof (comparefn) = 'function ');
Function compare (x, y ){
If (x = y) return 0;
If (custom_compare ){
Return comparefn. Call (null, x, y );
}
...
}
However, after testing, we found that this was not true. In Chrome 16.0.912.77 M, No optimization was executed. Alert came out with true, which is the same as ff and other browsers.
Therefore, this should not exist in all chrome versions, so it cannot be final.
The test result does not cover all chrome versions. Please note the error.
For more information, see http://www.cnblogs.com/xesam /]
Address: http://www.cnblogs.com/xesam/archive/2012/02/03/2336921.html