AOP(面向切面的编程)主要是将一些与核心业务逻辑模块无关的功能抽离出来,这些功能通常包括日志统计,安全控制,或者是异常处理等等. 我们要做的就是拓展Function.prototype来“动态植入”到业务的逻辑模块儿中,保持业务逻辑的纯净和高内聚. 现在我们有一个函数 var myFunc = function(){ console.log(1); } myFunc(); //1 那我们如何植入一个函数,让他在这个函数执行之前执行呢? 现在我们来拓展一个before函数. var myFunc…