面向切面实现
作者:
weil107 | 来源:发表于
2019-11-18 16:43 被阅读0次/**
* 执行之前
**/
Function.prototype.before = function (beforeFn) {
let _self = this
return function() {
beforeFn.apply(this, arguments)
return _self.apply(this, arguments)
}
}
/**
* 执行之后
**/
Function.prototype.after = function (afterFn) {
let _self = this
return function() {
let after = _self.apply(this, arguments)
afterFn.apply(this, arguments)
return after
}
}
let f = function(){
console.log(1)
}
let a = function a () {
console.log(0)
}
let b = function b () {
console.log(2)
}
f = f.before(a).after(b)
f()

js钩子实例.png
本文标题:面向切面实现
本文链接:https://www.haomeiwen.com/subject/dhlbictx.html
网友评论