An Interest In:
Web News this Week
- April 27, 2024
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
April 12, 2022 03:04 pm GMT
Original Link: https://dev.to/shamgurav96/shorten-the-consolelog-25h8
Shorten The Console.log
Tired of writing console.log() again and again ??? the the following JS tip is for you .
You can shorten the log() function with the help of Function.prototype.bind .
Since ES5, all functions have a bind method that allows one to create a new function specifying the context.
Use bind method to pre-define the context execution to always point to console. This way, no matter how the function is invoked, we are instructing the JavaScript engine to always set the context execution to console.
const C = console.log.bind(console);C("Downloaded Successfully !!!");// Downloaded Successfully !!!C("Code Executed Successfully !!!");// Code Executed Successfully !!!
Original Link: https://dev.to/shamgurav96/shorten-the-consolelog-25h8
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To