js fun.apply 装饰器(重新定义一个函数)

来源:互联网 发布:网络广告公司价格表 编辑:程序博客网 时间:2024/05/29 03:55

参考链接   https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Function/apply


用法  :

func.apply(thisArg, [argsArray])   


备注:

thisArg  指定函数运行时候的this,  在非严格模式 指定unll  undefined,会自动的导向全局(window对象)。


var count = 0,oldParseInt = parseInt;window.parseInt = function () {    count +=1;    return oldParseInt.apply(null, arguments);}parseInt('111');parseInt('222');parseInt('333');parseInt('333');console.log(count);

原创粉丝点击