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. MongoDB实战指南(六):MongoDB复制集之复制集概述

    1. 复制集概述 数据库总是会遇到各种失败的场景,如网络连接断开.断电等,尽管journaling日志功能也提供了数据恢复的功能,但journaling通常是针对单个节点来说的,只能保证单节点数据的一 ...

  2. linux 和 ecos 内核线程创建/信号量/event等对比

    ecos: int gx_thread_create (const char *thread_name, gx_thread_id *thread_id, void(*entry_func)(void ...

  3. 很受欢迎的Linux笔记(短小精悍)

    http://blog.csdn.net/xsl1990/article/details/8274028 如何知道所使用的LINUX是哪个发行版? lsb_release -a 查找某个文件的另类方法 ...

  4. SLF4J user manual

    http://www.slf4j.org/manual.html The Simple Logging Facade for Java (SLF4J) serves as a simple facad ...

  5. uva 11646 - Athletics Track

    题意:如图,体育场的跑道一圈是400米,其中弯道是两段半径相同的圆弧.已知矩形的长宽比例为a:b,求长和宽的具体数值. 注意:圆弧的圆心在纵轴线上! #include<iostream> ...

  6. bzoj1056

    花了一上午大概复习了一下splay,treap 像这种裸的数据结构题在js应该会越来越少 不过练练手也好, 这就是平衡树+hash,如果这是单纯的BST应用,还是写treap吧,好调试 ;       ...

  7. NuGet -- 如何创建及发布自己的程序包

    STEP 1:在NuGet上注册并获取API Key    首先,你需要在NuGet(https://www.nuget.org/)上注册一个新的账号,然后在My Account页面,获取一个API ...

  8. Sharepoint 2010 用VS定制Master,并且每个Web应用同一个Master

    转:http://***/html/blogs/20130407/1381.htm 最近做了一个项目管理系统,要求用Sharepoint,有个特别的功能就是通过创建出来的子站点要求应用同一个Maste ...

  9. hdu-5364 Distribution money

    http://acm.hdu.edu.cn/showproblem.php?pid=536 Distribution money Time Limit: 2000/1000 MS (Java/Othe ...

  10. css表格表头表尾固定,表身滚动

    表头表尾固定,表身滚动实现用了3个table标签 <!DOCTYPE html> <html> <head> <meta http-equiv="C ...