欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

完美解決IE低版本不支持call與apply的問(wèn)題

 更新時(shí)間:2013年12月05日 09:53:25   作者:  
這篇文章主要是對(duì)解決IE低版本不支持call與apply的問(wèn)題進(jìn)行了詳細(xì)的介紹。需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助
Function.prototype的apply和call是在1999年發(fā)布的ECMA262 Edition3中才加入的(1998年發(fā)布ECMA262 Edition2)。在此前的的瀏覽器如IE5.01(JScript 5.0)中是沒(méi)有apply和call的。因此會(huì)帶來(lái)一些兼容性問(wèn)題,以下是修復(fù)方式:
復(fù)制代碼 代碼如下:

if(!Function.prototype.apply){
    Function.prototype.apply = function(obj, args){
        obj = obj == undefined ? window : Object(obj);//obj可以是js基本類型
        var i = 0, ary = [], str;
        if(args){
            for( len=args.length; i<len; i++ ){
                ary[i] = "args[" + i + "]";
            }
        }
        obj._apply = this;
        str = 'obj._apply(' + ary.join(',') + ')';
        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<len; i++ ){
            args[i-1] = arguments[i];
        }
        return this.apply(obj, args);
    };
}

相關(guān)文章

最新評(píng)論