一、什么是AOP编程
AOP(Aspect-oriented programming)是面向切面的编程。能够在不修改原有代码的状况下增长新功能。
bash
二、例如:app
Function.prototype.before = function (fn) {
let that = this;
return function () { // => 当前返回的函数就是newFn
fn.apply(that,arguments); // {0:123,1:456}
that.apply(that, arguments);
}
}
let fn = function (val) {
console.log('old~~~~',val);
}
let newFn = fn.before(function(){
console.log('new~~~');
});
newFn('123');复制代码