一、什麼是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');複製代碼