ES6 Rest operator

by andyjmeyers

HTML

<div id='test1'></div>
<div id='test2'></div>
<div id='test3'></div>
<div id='test4'></div>
<div id='test5'></div>
<div id='test6'></div>

JavaScript

var pluto ="pluto",
    charon = "charon",
    othermoons = ["styx", "nix", "kerberos", "hydra"];

function test1(...a){
    return JSON.stringify({a:a});   
}

function test2(a, ...b){
    return JSON.stringify({a:a, b:b});   
}

function test3(a, b, ...c){
    return JSON.stringify({a:a, b:b, c:c});   
}


document.getElementById("test1").innerHTML ="1. " +  test1(pluto);
document.getElementById("test2").innerHTML ="2. " +  test1(pluto, charon, othermoons);
document.getElementById("test3").innerHTML ="3. " +  test2(pluto, charon, othermoons);
document.getElementById("test4").innerHTML ="4. " +  test2(undefined, pluto, charon, othermoons);
document.getElementById("test5").innerHTML ="5. " +  test3(pluto, charon, othermoons);
document.getElementById("test6").innerHTML ="6. " +  test3(pluto);