DEV Community

LG
LG

Posted on

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)