DEV Community

LG
LG

Posted on

2 2

Delay console.log()

Examine this short snippet within two scenarios given :

stream.on('some-event', console.log("hello world")) // comment : this won't wait for some-event being triggered (no delay) i.e. should trigger right away – this is not we want to happen !
stream.on('some-event', console.log.bind(null, "hello world")) // comment : this wait for some-event being triggered (delayed)
Enter fullscreen mode Exit fullscreen mode

In React this would be achieved by encapsulating console.log into fat arrow function wrapper as so (this is common practice) :

stream.on('some-event', ()=>console.log("hello world"))
Enter fullscreen mode Exit fullscreen mode

TL;DR : By delaying we "kinda" mocking scenario of console.log.preventDefault() idiomatically .


If any typos found or suggestions could be made , please leave a comment below !

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay