A method of injection js
Many java framework to support apo injection, js can also be carried out to achieve a similar
Js mainly through the extension of the method of ancestors to implement a Function object.
Function.prototype.after = function(foo) {
const thiz = this;
return function(...args) {
thiz.apply(thiz, args);
foo.apply(thiz, args);
}
}
//test
function test(param) {
console.log("do");
}
function doAfter(param) {
console.log("doAfter");
}
const doWithAfter = test.after(doAfter);