We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
装饰者模式可以动态地给某个对象添加一些额外的职责,而不会影响从这个类中派生的其他对象。
Function.prototype.before = function(beforeFn){ var self = this; return function(){ beforeFn.apply(this,arguments); return self.apply(this,arguments); } } Function.prototype.after = function(afterFn){ var self = this; return function(){ var result = self.apply(this,arguments); afterFn.apply(this,arguments); return result; } }
var login = function(){ console.log('login') } var log = function(){ console.log('user login') } login = login.after(log); login();
var login = function(type,url,param){ console.log(param) } var getToken = function(){ return 'token' } login = login.before(function(type,url,param){ param.token = getToken(); }) login('get','http://baidu.com',{ name: 'hello' });
var submit = function(){ console.log('submit form') } var validate = function(){ console.log('validate form') } submit = submit.before(validate); submit();
The text was updated successfully, but these errors were encountered:
No branches or pull requests
装饰者模式可以动态地给某个对象添加一些额外的职责,而不会影响从这个类中派生的其他对象。
数据统计
改变参数
表单验证
The text was updated successfully, but these errors were encountered: