Monitor Occasions and Perform Calls through Console

0
2

Regardless of having labored on the very advanced Firefox for a lot of years, I am going to all the time 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 offers monitorEvents and monitor so as to get a log every time an occasion happens or operate is named?

Monitor Occasions

Go a component and a sequence of occasions to monitorEvents to get a console log when the occasion occurs:

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

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

You’ll be able to go an array of occasions to pay attention for a number of occasions. The logged occasion represents the identical occasion you’d see in case you manually referred to as addEventListener.

Monitor Perform 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 which you could view the arguments offered, which is nice for inspecting.

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

  • JavaScript and CSS Spinners with spin.js
  • iPad Detection Using JavaScript or PHP

    The most well liked gadget on the market proper now appears to be the iPad. iPad this, iPad that, iPod your mother. I am underwhelmed with the gadget however that does not imply I should not attempt to account for such units on the web sites I create. In Apple’s…


LEAVE A REPLY

Please enter your comment!
Please enter your name here