1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| Function.prototype.before = function(callBack){ let that = this; return function(){ callBack() that.apply(that, arguments) } }
function fn(data){ console.log('原函数', data) }
function cb(){ console.log('callBack') }
let newFn = fn.before(cb)
newFn(123)
|