Skip to content

Flexible Javascript arguments, like Python’s *args

When I started working with Python, *args was very handy and I started to miss it in my Javascript projects. Only recently, I found out you can get an arguments object of the function’s arguments like this:

function func() {
    console.log(arguments); // outputs: ["Earth", "Wind", "Fire"]
}

func("Earth", "Wind", "Fire")

Nice for functions where you want a flexible argument length!

 

 


No Comments ( Add comment / trackback )

Post a comment

(required)
(required)

Your email is never published nor shared.

(optional)
Allowed HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>