Problem with the ES5:
function displayTags(){ for (let i in arguments) { let tag = arguments[i]; _addToTopic(tag); } }
function displayTags(targetElement){ let target = _findElement(targetElement); for (let i in arguments) { let tag = arguments[i]; // break the loop, since the first arguments is no longer a tag _addToTopic(target, tag); } }
Improvement from ES6:
// Cannot assign default value to Rest Parameter // Rest Parameter should alwasys come at the last const displayTags = (blogName="New Blog", ...tags) => { console.log(blogName, tags); } displayTags("ES2015", "Javascript", "ES6", "Babel");
原文:http://www.cnblogs.com/Answer1215/p/5095361.html