You cannot currently join array arguments because they are not an array, shown here
so you need to either first turn them into an array like this,
function f() { var args = Array.prototype.slice.call(arguments, f.length); return 'the list: ' + args.join(','); }
or like that, a little shorter
function displayIt() { return 'the list: ' + [].join.call(arguments, ','); }
if you use something like babel or a compatible browser to use es6 functions, you can also do this with rest arguments.
function displayIt(...args) { return 'the list: ' + args.join(','); } displayIt('111', '222', '333');
which allows you to do even cooler things like
function displayIt(start, glue, ...args) { return start + args.join(glue); } displayIt('the start: ', '111', '222', '333', ',');
Ryan White Sep 29 '15 at 19:28 2015-09-29 19:28
source share