Skip to content

Instantly share code, notes, and snippets.

@think2011
Created July 30, 2015 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save think2011/7f4ffa65731d81db177d to your computer and use it in GitHub Desktop.
Save think2011/7f4ffa65731d81db177d to your computer and use it in GitHub Desktop.
装饰者模式,after | before
Function.prototype.after = function (fn) {
var that = this;
return function () {
var ret = that.apply(this, arguments);
fn.apply(this, arguments);
return ret;
};
};
Function.prototype.before = function (fn) {
var that = this;
return function () {
fn.apply(this, arguments);
return that.apply(this, arguments);
};
};
var showLogin = function () {
console.log('打开登陆框');
};
showLogin = showLogin.after(function () {
console.log('上报登录统计');
});
showLogin();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment