Function.prototype.before = function (beforefn) { var _self = this; return function () { beforefn.apply(this, arguments); return _self.apply(this, arguments); }; }; var func = function (param) { console.log(param); }; func =func.before( function (param) { param.b = ‘b‘; }); func({a:‘a‘});
Function.prototype.before = function (beforefn) { var _self = this; return function () { beforefn.apply(this, arguments); return _self.apply(this, arguments); }; }; var getToken = function () { return ‘token‘; }; var ajax = function (type, url, param) { console.log(param); }; ajax = ajax.before(function (type,url,param) { param.Token = getToken(); }); ajax(‘get‘,‘http://xx.com/getuseinfo‘,{name:‘test‘});
原文:http://www.cnblogs.com/meiyh/p/6514845.html