包装函数

function wrap(object,method,wrapper){    //object:包装方法所属对象  method:方法名   wrapper:替换函数
    var fn = object[method];
    return object[method] = function(){
        return wrapper.apply(this,[fn.bind(this)].concat(Array.prototype.slice.call(arguments)));
    };
}

 

posted @ 2017-11-11 17:56  halo-漾  阅读(178)  评论(0编辑  收藏  举报