Full-time web dev; JS lover since 2002; CSS fanatic. #CSSIsAwesome
I try to stay up with new web platform features. Web feature you don't understand? Tell me! I'll write an article!
He/him
I find rest parameters super useful for writing wrapper functions. For a super simple example, I often like to define small logger functions as wrappers around console.log() that always add certain context, such as a label that tells me where the log was issued:
This is a pretty trivial example, but I've used it for much more complicated cases where I basically always use the same default arguments for calls to library functions with lots of arguments, and I want a wrapper that supplies all but the last couple arguments for me. I'll write a wrapper that gathers arguments into a rest array, then spreads them into the end of my call to the library function, like I did with console.log above
I find rest parameters super useful for writing wrapper functions. For a super simple example, I often like to define small logger functions as wrappers around
console.log()
that always add certain context, such as a label that tells me where the log was issued:This is a pretty trivial example, but I've used it for much more complicated cases where I basically always use the same default arguments for calls to library functions with lots of arguments, and I want a wrapper that supplies all but the last couple arguments for me. I'll write a wrapper that gathers arguments into a rest array, then spreads them into the end of my call to the library function, like I did with
console.log
aboveThis is super awesome. I can see the value already! Thank you so much! 😁