调用apply报错:CreateListFromArrayLike called on non-object;

Function.apply(obj, args)方法能接收两个参数  
obj:这个对象将代替Function类里this对象  
args:这个是数组,它将作为参数传给Function(args-->arguments) 
    var oldParseInt = parseInt;
    console.log(oldParseInt("10"));
    var count = 0;
    window.parseInt = function(){
        count+=1;
        // return oldParseInt(arguments[0]);
        return oldParseInt.apply(null,arguments[0]);
    }

因为第二个参数没传数组,所以报了这个错误。

正确写法为:

    var oldParseInt = parseInt;
    console.log(oldParseInt("10"));
    var count = 0;
    window.parseInt = function(){
        count+=1;
        // return oldParseInt(arguments[0]);
        return oldParseInt.apply(null,arguments);
    }

 

<JavaScript>调用apply报错:CreateListFromArrayLike called on non-object;

上一篇:从Paxos到ZooKeeper-一、分布式架构


下一篇:h5页面测试与原生APP页面测试的区别