Tuesday, March 28, 2023
HomeSoftware DevelopmentMonitor Occasions and Operate Calls through Console

Monitor Occasions and Operate Calls through Console

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

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 move an array of occasions to hear for a number of occasions. The logged occasion represents the identical occasion you’d see in case you manually known as addEventListener.

Monitor Operate Calls

The monitor methodology means that you can hear for calls on a particular operate:

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

// Utilization 1: Primary name
// operate myFn known as

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

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

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

  • Chris Coyier’s Favorite CodePen Demos II

    Hey everybody! Earlier than we get began, I simply wish to say it is rattling exhausting to choose this few favorites on CodePen. Not as a result of, as a co-founder of CodePen, I really feel like a dad selecting which child he likes finest (RUDE). However as a result of there’s simply so…

  • Add Controls to the PHP Calendar



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments