Answer the question
In order to leave comments, you need to log in
Is there an add-on over the constructor so that when a method is called from the prototype, some function is called before that?
For example, there is a constructor and a couple of prototypes:
module.exports = new Quick;
function Quick() {
this.task = [];
}
Quick.prototype.sync = function() {
this.task.push('sync')
}
Quick.prototype.js = function() {
this.task.push('js')
}
Quick.prototype.mocha = function() {
this.task.push('mocha')
}
Answer the question
In order to leave comments, you need to log in
function Quick() {
var self = this;
self.task = [];
Object.keys(self.constructor.prototype).forEach(function (key) {
var orig = self.constructor.prototype[key];
self.constructor.prototype[key] = function () {
self.task.push(key);
return orig.apply(self, arguments);
};
};
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question