Home > Web Front-end > JS Tutorial > Fix the sort method of IE9&Safari_javascript skills

Fix the sort method of IE9&Safari_javascript skills

WBOY
Release: 2016-05-16 18:00:41
Original
1090 people have browsed it

The current version v0.2
v0.1 Fixed the regret that IE9--Array.prototype.sort cannot be sorted according to object attributes
v0.2 Fixed the problem that Safari does not support function parameters

Copy code The code is as follows:


!function(window){
var ua = window.navigator.userAgent.toLowerCase (),
reg = /msie|applewebkit.safari/;
if(reg.test(ua)){
var _sort = Array.prototype.sort;
Array.prototype.sort = function(fn){
if(!!fn && typeof fn === 'function'){
if(this.length < 2) return this;
var i = 0, j = i 1, l = this.length, tmp, r = false, t = 0;
for(; i < l; i ){
for(j = i 1; j < l; j ){
t = fn.call(this, this[i], this[j]);
r = (typeof t === 'number' ? t :
!!t ? 1 : 0) > 0
? true : false;
if(r){
tmp = this[i];
this[i] = this[j];
this[j] = tmp;
}
}
}
return this;
}else{
return _sort.call(this);
}
};
}
}(window);
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template