Wednesday, February 8, 2023
HomeSoftware DevelopmentMonitor Occasions and Perform Calls by way of Console

Monitor Occasions and Perform Calls by way of Console


Regardless of having labored on the very advanced Firefox for quite a few years, I am going to at all times love plain previous 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 supplies monitorEvents and monitor so that you could get a log every time an occasion happens or operate is named?

Monitor Occasions

Go a component and a collection 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 possibly can move an array of occasions to pay attention for a number of occasions. The logged occasion represents the identical occasion you’d see when you manually known 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 known as

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

I actually like you can view the arguments offered, which is nice for inspecting.

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

  • CSS Text Overlap

    One of many essential capabilities of CSS is to place parts. Margin, padding, high, left, proper, backside, place, and z-index are just some of the key gamers in CSS positioning. Through the use of the above spacing…

  • Spyjax:  Ajax For Evil Using Dojo

    The thought of Spyjax is nothing new. In pasts posts I’ve coated how one can spy in your person’s historical past with each MooTools and jQuery. Right this moment we’ll cowl how you can examine person historical past utilizing the Dojo Toolkit. The HTML For the sake of this…



Supply hyperlink
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments