Monitor Occasions and Operate Calls by way of Console


Regardless of having labored on the very complicated Firefox for a lot of years, I am going to at all times love plain outdated console.log debugging. Logging can present an audit path as occasions occur and textual content you’ll be able to share with others. Do you know that chrome gives monitorEvents and monitor to be able to get a log every time an occasion happens or operate known as?

Monitor Occasions

Move a component and a collection of occasions to monitorEvents to get a console log when the occasion occurs:

// Monitor any clicks throughout the window
monitorEvents(window, 'click on')

// Monitor for keyup and keydown occasions on the physique
monitorEvents(doc.physique, ['keyup', 'keydown'])

You may cross an array of occasions to pay attention for a number of occasions. The logged occasion represents the identical occasion you’d see if you happen to manually referred to as addEventListener.

Monitor Operate Calls

The monitor technique permits you to pay attention for calls on a particular operate:

// Outline a pattern operate
operate myFn() { }
// Monitor it
monitor(myFn)

// Utilization 1: Primary name
myFn()
// operate myFn referred to as

// Utilization 2: Arguments
myFn(1)
// operate myFn referred to as with arguments: 1

I actually like that you may view the arguments supplied, which is nice for inspecting.

I normally go for logpoints as a substitute of embedding console statements in code, however monitor and monitorEvents present a substitute for each.

  • Facebook Open Graph META Tags

    It is no secret that Fb has develop into a significant site visitors driver for every type of internet sites.  These days even giant firms steer customers towards their Fb pages as a substitute of the company web sites instantly.  And naturally there are Fb “Like” and “Advocate” widgets on each web site.  One…

  • Detect DOM Node Insertions with JavaScript and CSS Animations

Latest articles

Related articles

Leave a reply

Please enter your comment!
Please enter your name here