Javascript Method interceptors

There are often cross cutting concerns in your app, such as logging, security checkpoints and or maybe business validations. This is a very simple approach of implementing method interceptors in pure javascript. The crux: This decorates all the methods for the given object with before and after interceptions. intercept: function(o) { for (let p in o) { if (typeof o[p] === 'function') { let c = o[p]; o[p] = function() { MIFactory.beforeExecution(o, p); let r =, arguments); MIFactory.afterExecution(o, p); return r; } } } return o; } method interceptor factory: MIFactory = { interceptors: [], register: function(interceptor) { MIFactory.interceptors.push(interceptor); }, unregister: function(