Two ways I discovered to pass dynamic (arrow and non-arrow) function parameters
In my attempt to understand how the clsx utility is written by looking at its source code, I found that clsx does not have function parameters declared.
How is it possible to access the parameters without declaring them? clsx expects dynamic parameters. Below is an usage example from the docs
Then, I looked at the function code and from the lines below, it was apparent that through arguments variable, it is possible to access the function parameters.
export function clsx() { var i=0, tmp, x, str='', len=arguments.length;
I searched on Google with this query “arguments without paramters in nodejs” and clicked on the first Stackoverflow link.
The arguments object is useful for functions called with more arguments than they are formally declared to accept. This technique is useful for functions that can be passed a variable number of arguments.
Using arguments only works in non-arrow functions.
I read in some open source code sometime ago (I think, it is nextjs source code), don’t exactly remember but, you could use spread operator to accept dynamic function parameters. I found this stackoverflow question.
Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.