mardi 6 décembre 2016

common function that accept all argument in javaScript

often time I have this pattern problem in javascript. I have an add function

function add(a, b){ return a + b; }

then I can do add(1,2) //3

but what if I want to pass in any length of arguments?

I can't do freely add(1,2,3,4). or add(something,something,something). If I want I have to write another add function that accept 4 and 3 arguments.

I know I can use loop them up by loop but how to pass any number of argument to a function in js?

Aucun commentaire:

Enregistrer un commentaire