Rest Parameters:

In ES5, when you don't know how many paramters will be passed in, you can use arguments:

let sum = function(){
let result = 0;
for(let i = 0; i < arguments.length; i++){
result += arguments[i];
}
return result;
} let result = sum(1,2,3);

In ES6, you can use Rest params:

let sum = function(...numbers){

    let result = 0;
for(let i = 0; i < numbers.length; i++){
result += numbers[i];
}
return result;
};
describe("rest paramters", function(){

    it("is like varargs", function(){

        let doWork = function(name, ...numbers){

            let result = 0;
numbers.forEach(function(n){
result += n;
}); return result;
}; let result = doWork("Scott", 1,,2,3);
expect(result).toBe(6);
});
});

...Spread:

It looks the same as Rest Parameters, Spread uses to spread an array.

it("should sum up", function(){
let doWork = function(x,y,z){
return x+y+z;
}; expect(doWork(...[1,2,3])).toBe(6);
});
<!DOCTYPE html>
<html>
<head>
<script data-require="traceur@*" data-semver="0.0.0-20140302" src="https://traceur-compiler.googlecode.com/git/bin/traceur.js"></script>
<script>
traceur.options.experimental = true;
</script>
<script data-require="traceur@*" data-semver="0.0.0-20140302" src="https://traceur-compiler.googlecode.com/git/src/bootstrap.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head> <body>
<script type="module">
let a = [4,5,6];
let b = [1,2,3, ...a, 7,8,9];
document.write(b); //1,2,3,4,5,6,7,8,9
</script>
</body>
</html>

[ES6] 23. Rest Parameters & Spread Parameters的更多相关文章

  1. ADOQuery.Parameters: Property Parameters does not exist

    Exception class EReadError with message 'Property Parameters does not exist'. Exception class EReadE ...

  2. Typescript & React & optional parameters & default parameters

    Typescript & React & optional parameters & default parameters Typescript & optional ...

  3. [ES6] Array -- Destructuring and Rest Parameters && for ..of && Arrat.find()

    We can use the destructing and rest parameters at the same time when dealing with Array opration. Ex ...

  4. 【转】es6的拓展运算符 spread ...

    原文:https://blog.csdn.net/qq_30100043/article/details/53391308 The rest parameter syntax allows us to ...

  5. ...:ES6中扩展运算符(spread)和剩余运算符(rest)详解

    1.扩展运算符(spread) demo1:传递数据代替多个字符串的形式 let test= function(a,b,c){ console.log(a); console.log(b); cons ...

  6. Database Initialization Parameters for Oracle E-Business Suite Release 12 (文档 ID 396009.1)

    In This Document Section 1: Common Database Initialization Parameters For All Releases Section 2: Re ...

  7. Device trees, Overlays and Parameters of Raspberry Pi

    Raspberry Pi's latest kernels and firmware, including Raspbian and NOOBS releases, now by default us ...

  8. SPRING IN ACTION 第4版笔记-第五章BUILDING SPRING WEB APPLICATIONS-004-以query parameters的形式给action传参数(@RequestParam、defaultValue)

    一. 1.Spring MVC provides several ways that a client can pass data into a controller’s handler method ...

  9. Oracle Net Listener Parameters (listener.ora)(转)

    12/20 7 Oracle Net Listener Parameters (listener.ora) This chapter provides a complete listing of th ...

随机推荐

  1. 第七章Bulk设备

    小川工作室编写,本书为LM3S的USB芯片编写,上传的均为草稿,还有没修改,可能还有很多地方不足,希望各位网友原谅! QQ:2609828265 TEL:15882446438 E-mail:paul ...

  2. FireMonkey vs. VCL (FMX的UI更灵活,图形效果更强,硬件加速,内嵌3D,使用浮点数更精确,跨平台,可使用Mida converter转换和TFireMonkeyContainer内嵌)

    Frequently when I am talking about the VCL or FireMonkey I get some of these common questions: Is VC ...

  3. 使用GDI+ DrawDriverString实现行距及字符间距控制

    主要是要将一个标题和几段文字绘制到固定大小的图片上,如果一张放不下就生成多张.在使用DrawString是发现无法控制行距 namespace TibetTest {     public class ...

  4. 【 D3.js 选择集与数据详解 — 1 】 使用datum()绑定数据

    选择集和数据的关系是 D3 最重要的基础,在[入门 - 第 7 章]时进行过些许讲解,对于要掌握好 D3 是远远不够的.故此开设一个新的分类,专门讨论选择集与数据的关系,包括数据绑定的使用和工作原理, ...

  5. 使用 HTML5、CSS3 和 MathML 在 EPUB 3 中制作版式丰富的出版物

    探索用于高级排版和印刷的新一代开放电子书标准 EPUB 3.0 是最新的行业标准 XML 电子书格式,它采用了 HTML5 和 CSS3,因而融入了现代 Web 技术.它重点关注 XML 驱动的工具包 ...

  6. CodeForces 370A Rook, Bishop and King

    此题看似很简单,但实际上有不少细节,WA点不少.分情况处理即可. #include<cmath> #include<cstdio> #include<string> ...

  7. Request Connection: Remote Server @ 192.229.145.200:80

    录制Loadrunner脚本时,提示: Request Connection: Remote Server @ 192.229.145.200:80   NOT INTERCEPTED!(REASON ...

  8. ESB、SOA、EAI异同【转】

    先说概念:       ESB:企业服务总线(ESB : Enterprise Service Bus):ESB 是一种开放的.基于标准的分布式同步或异步信息传递中间件.通过 XML.Web Serv ...

  9. 图解SVD分解

    参考 http://www.bfcat.com/index.php/2012/03/svd-tutorial/

  10. spoj 8222 Substrings(后缀自动机+DP)

    [题目链接] http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=28005 [题意] 给一个字符串S,令F(x)表示S的所有长度为 ...