In addition to these answers, you can also write a utility that will wrap the methods of the object with logging:
It will be like this:
function addLogging(object) { Object.keys(object).forEach(function (key) { if (typeof object[key] === 'function') { var originalFn = object[key]; object[key] = function () { console.log('before calling', key); var result = originalFn.apply(this, arguments); console.log('after calling', key); return result; } } }); }
You can use lodash wrap to help you.
I have long answered the question about something similar, like the code above: jQuery logger plugin
He did not handle the constructors perfectly, so he had such problems. The resulting code is fixed here.
You can also look at sinon.js , it provides spyware and can determine the order in which spied functions are called. But there can be too much for this, and it can slow down a little.
This method is common in aspect programming . You can search about this and maybe try using the AOP library. meld is popular.
Also, instead of console.log in chrome, you can use console.timeline , which gives you greater visibility when used properly.
Farid nouri neshat
source share