关于 ie8不兼容的一些方法
2024-09-03 08:14:00
ie8 不兼容的方法
$(function(){
//添加数组IndexOf方法
if (!Array.prototype.indexOf){
Array.prototype.indexOf = function(elt /*, from*/){
var len = this.length >>> 0; var from = Number(arguments[1]) || 0;
from = (from < 0)
? Math.ceil(from)
: Math.floor(from);
if (from < 0)
from += len; for (; from < len; from++){
if (from in this && this[from] === elt)
return from;
}
return -1;
};
} //getOwnPropertyNames keys 方法
if(!Object.getOwnPropertyNames || !Object.keys){
Object.keys = Object.getOwnPropertyNames = function(temp){
var A = [];
for(var key in temp){
A.push(key);
}
return A;
}
} //forEach 方法
if ( !Array.prototype.forEach ) {
Array.prototype.forEach = function forEach( callback, thisArg ) {
var T, k;
if ( this == null ) {
throw new TypeError( "this is null or not defined" );
}
var O = Object(this);
var len = O.length >>> 0;
if ( typeof callback !== "function" ) {
throw new TypeError( callback + " is not a function" );
}
if ( arguments.length > 1 ) {
T = thisArg;
}
k = 0;
while( k < len ) {
var kValue;
if ( k in O ) {
kValue = O[ k ];
callback.call( T, kValue, k, O );
}
k++;
}
};
} //filter 方法
if (!Array.prototype.filter)
{
Array.prototype.filter = function(fun /*, thisArg */)
{
"use strict"; if (this === void 0 || this === null)
throw new TypeError(); var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function")
throw new TypeError(); var res = [];
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
for (var i = 0; i < len; i++)
{
if (i in t)
{
var val = t[i]; // NOTE: Technically this should Object.defineProperty at
// the next index, as push can be affected by
// properties on Object.prototype and Array.prototype.
// But that method's new, and collisions should be
// rare, so use the more-compatible alternative.
if (fun.call(thisArg, val, i, t))
res.push(val);
}
} return res;
};
}
})
最新文章
- gentoo 安装
- DataSnap 2009 系列之三 (生命周期篇)
- Perl 随笔
- a various of context
- git 恢复工作区删除的所有文件
- List集合分组
- Android 使用Android Studio + Gradle 或 命令行 进行apk签名打包
- SSD的基本架构
- 打印Ibatis最后,SQL声明
- html 5 本地数据库(Web Sql Database)核心方法openDatabase、transaction、executeSql 详解
- Java 8中Stream API学习笔记
- python的条件语句
- java 完全解耦
- php支付宝开发
- Excel 公式CORREL算出相关系数
- VIM各种快捷应用
- PostgreSQL 资源
- 从知乎了解到,为什么Mysql禁用存储过程、外键和级联?
- js区分字符串和数字,有时候需要将字符串转换成数字
- js动画杂记