Created
July 30, 2015 07:12
-
-
Save think2011/7f4ffa65731d81db177d to your computer and use it in GitHub Desktop.
装饰者模式,after | before
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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