Rest and Spread Operators.md

Why we need rest and spread operators?

var showCollections = function(id, ...collection){
console.log(collection instanceof Array);
};
showCollections(42, 'movies', 'music');

instanceof

The instanceof operator tests whether the prototype property of a constructor appears anywhere in the prototype chain of an object.

a demo about the propety of the instance.

function C(){}
function D() {} var o = new C();
o instanceof C; o instanceof D; o instanceof Object; C.prototype instanceof Object;
C.prototype = {};
var o2 = new C(); o2 instanceof C;
o instanceof C; D.prototype = new C();
var o3 = new D(); o3 instanceof D;
o3 instanceof C;

var showCollections = function(id, ...collection){
console.log( arguments.length);
}
showCollections (123, 'movies', 'music');

var showCollections = function(id, ...collection) {
console.log(collection);
};
showCollections(42, 'movies', 'music' );

var showCollections = function(id, ...collection){};
console.log(showCollections.length);

The length property ignores the Rest Parameter.

var showCollections = function(id, ...collection){
console.log(arguments.length);
}; showCollections(123, 'movie', 'music');

var getFirst = new Function("...args"," return args[0]");
console.log(getFirst(1,2));

The Spread Operator

Spread Operator spreads out an array and passed the values into the specified function.

It used into an arrry

let values = [300, 400, 500];
let newSet = [100, ...values, 500]; console.log(newSet);

In ES6,you have the ability to pass a function a dynamic number of parameters very easily.If you want to do this in ES5,you would have to put all the values in a data container data type like an array.

let numbers = [-25, 100, 42, -1000 ];
console.log(Math.max(...numbers,900));

function printInput(...input){
console.log(input);
} let input = [,,];
printInput(...input);

ES6 new syntax of Rest and Spread Operators的更多相关文章

  1. ES6 new syntax of Default Function Parameters

    Default Function Parameters.md Default Function Parameters function getSum(a,b){ a = (a !== undefine ...

  2. ES6 new syntax of Arrow Function

    Arrow Function.md Arrow Functions The basic syntax of an arrow function is as follows var fn = data ...

  3. ES6 new syntax of let and const (one)

    variable declarations : let, const,and block scope why we redefine the way about declarations? funct ...

  4. 用简单的方法学习ES6

    ES6 简要概览 这里是ES6 简要概览.本文大量参考了ES6特性代码仓库,请允许我感谢其作者@Luke Hoban的卓越贡献,也感谢@Axel Rauschmayer所作的[优秀书籍]//explo ...

  5. 逆转序列的递归/尾递归(+destructuring assignment)实现(JavaScript + ES6)

    这里是用 JavaScript 做的逆转序列(数组/字符串)的递归/尾递归实现.另外还尝鲜用了一下 ES6 的destructuring assignment + spread operator 做了 ...

  6. [HIve - LanguageManual] Hive Operators and User-Defined Functions (UDFs)

    Hive Operators and User-Defined Functions (UDFs) Hive Operators and User-Defined Functions (UDFs) Bu ...

  7. 了解ES6

    内容: 1.ES6介绍及基础 2.模块.类和继承 3.ES6高级特性 4.Generator和Iterator 5.异步编程 6.函数相关 内容参考:<ES6 标准入门> ES6标准阅读链 ...

  8. Js apply方法与call方法详解 附ES6新写法

    我在一开始看到javascript的函数apply和call时,非常的模糊,看也看不懂,最近在网上看到一些文章对apply方法和call的一些示例,总算是看的有点眉目了,在这里我做如下笔记,希望和大家 ...

  9. eslint Rules

    Rules 为了让你对规则有个更好的理解,ESLint 对其进行了分门别类. 所有的规则默认都是禁用的.在配置文件中,使用 "extends": "eslint:reco ...

随机推荐

  1. 00_Linux介绍_我的Linux之路

    原文章发布于特克斯博客www.susmote.com 什么是操作系统 操作系统(Operating System,简称OS)是管理和控制计算机硬件与软件资源的计算机程序,是直接运行在"裸机& ...

  2. mysql新手入门随笔3

    #求最高工资的员工信息 SELECT * FROM emp WHERE sal = (SELECT max(sal) FROM emp); #删除工资最低的员工信息 DELETE FROM emp W ...

  3. Android 源代码结构

    简介 在使用Andriod SDK进行应用程序开发的时候,我们需要对源代码进行调试,有可能需要进入到某个Android API函数内部进行跟踪调试.但是,如果目标版本的SDK没有关联对应版本的源代码的 ...

  4. Java基础学习笔记七 Java基础语法之继承和抽象类

    继承 继承的概念 在现实生活中,继承一般指的是子女继承父辈的财产.在程序中,继承描述的是事物之间的所属关系,通过继承可以使多种事物之间形成一种关系体系. 例如公司中的研发部员工和维护部员工都属于员工, ...

  5. img之间的间隙问题

    前言:关于基线(base line),中线(middle line),行高(line height)的了解还是比较浅的,所以引用前辈的成果,稍带解释下 1)行高:两行文字之间"基线" ...

  6. ios swift例子源码网址总结

    http://blog.csdn.net/woaifen3344/article/details/40079351 http://www.ruanman.net/swift/learn/4607.ht ...

  7. Java HashMap工作原理及实现

    Java HashMap工作原理及实现 2016/03/20 | 分类: 基础技术 | 0 条评论 | 标签: HASHMAP 分享到:3 原文出处: Yikun 1. 概述 从本文你可以学习到: 什 ...

  8. 微信支付get_brand_wcpay_request:fail

    最近做了微信支付功能,和后端一起踩坑中,微信一直报错:get_brand_wcpay_request:fail 出现该问题的原因: 1.生成的sign签名有问题 2.支付授权目录配置有问题 在经过仔细 ...

  9. 深入浅出 SSL 管理配置实战

    我们生活在一个信息大爆炸的时代,几乎每天都在和互联网打交道,购物.网银转账.支付宝付款.搜索信息.查看邮件.观看视频.微信聊天.上网冲浪.阅读新闻等,无不时时刻刻在和网络打交道.那如何保护网络安全就相 ...

  10. 你能选择出,前几个元素吗?使用纯css

    面试被问到 ,你能选择出前几个元素吗?括弧只能使用css 我当时是一脸懵逼... 回去的路上思考一路 终于想到了解决办法 虽然为时已晚 但是觉得很有意义... 首先要用到 否定选择器 : :not() ...