Home > Web Front-end > JS Tutorial > Perfectly solve the problem that lower versions of IE do not support call and apply_javascript skills

Perfectly solve the problem that lower versions of IE do not support call and apply_javascript skills

WBOY
Release: 2016-05-16 17:10:48
Original
1629 people have browsed it

Function.prototype's apply and call were only added in ECMA262 Edition3 released in 1999 (ECMA262 Edition2 was released in 1998). In previous browsers such as IE5.01 (JScript 5.0), there is no apply and call. Therefore, there will be some compatibility issues. Here are the fixes:

Copy code The code is as follows:

if(!Function.prototype.apply){
Function.prototype.apply = function(obj, args){
obj = obj == undefined ? window : Object(obj);//obj can be js basic type
var i = 0, ary = [], str;
if(args){
ary[i ] = "args[" i "]"; ;
try{
return eval(str);
}catch(e){
}finally{
delete obj._apply;
}
};
}
if(!Function.prototype.call){
Function.prototype.call = function(obj){
var i = 1, args = [];
for( len=arguments. length; i          args[i-1] = arguments[i];

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