Function.prototype.before = function (before) {
let that = this
return function () {
before.apply(that, arguments);
that.apply(that, arguments);
}
}
let fn = function (val) {
console.log('old', val)
}
let newFn = fn.before(function (val) {
console.log('new', val)
})
newFn('123');
// new 123
// old 123
说明:newFn方法没有改变fn,并且在fn前执行