Encontré este código, para agregar antes y después de la capacidad de ejecutar una función, busqué y no sé, ¿qué significa nuevo (yo) allí?
Function.prototype.before = function(fn) { const self = this return function() { fn.apply(new(self), arguments) return self.apply(new(self), arguments) } } Function.prototype.after = function(fn) { const self = this return function() { self.apply(new(self), arguments) return fn.apply(new(self), arguments) } } ... const validate = function(){ // ... } const formSubmit = function() { // ... ajax( 'http:// xxx.com/login', param ) } submitBtn.onclick = function() { formSubmit.before( validate ) }