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. java.lang.Object学习总结

  2. 201621123062《java程序设计》第二周学习总结

    1.本周学习总结 本周学习重点: 1.java的基本数据类型(类似于C,特有boolean),java的引用类型(类似指针),其他常用类. 2.字符串类型String(比c简单),String的不变性 ...

  3. fs输出文件目录

    var http = require("http"); var fs = require("fs"); var server = http.createServ ...

  4. java第5章学习总结

    学号20145336 <Java程序设计>第5周学习总结 教材学习内容总结 try catch JVM会先尝试执行try区块中的内容,若发生错误且与catch后面的类型相符,则执行catc ...

  5. 201421123042 《Java程序设计》第5周学习总结

    1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 接口 Comparable Arrays.sort -has a Lambda表达式 1.2尝试使用思维导图将这些关键词组织起来 ...

  6. 使用ArrayList时代码内部发生了什么(jdk1.7)?

    前言 ArrayList(这里的ArrayList是基于jdk1.7)是在项目中经常使用的集合类,例如我们从数据库中查询出一组数据.这篇文章不去剖析它的继承和实现,只是让我们知道实例化及增删改查时它的 ...

  7. Python之旅.第四章.模块与包.总结(未完待遇)

    一.模块 模块: 一系列功能的集合体,在python中一个py文件就是一个模块,模块名就是py文件的文件名: 模块的好处: 1.减少重复的代码 2.拿来主义 定义模块: 就是创建一个py文件: 使用模 ...

  8. C++ 实现一个信号量

    C++ 实现一个信号量 信号量有很多应用场景,事实上只要是生产者-消费者模型,一般都需要一个信号量来控制. POSIX接口是有PV信号量API的.但C++标准没有.下面是一个PV信号量的简单实现.有些 ...

  9. LAMP 搭建

    p { margin-bottom: 0.25cm; line-height: 120% } LAMP 搭建 承 Ubuntu 17.10.1安装, 定制. 参考 电子工业出版社, Ubuntu完美应 ...

  10. Spring Framework 的 Assert断言

    知识共享才能传播,博采众家之长,才能推陈出新!-- 参考 https://www.cnblogs.com/hwaggLee/p/4778101.html 一.什么是 Assert(断言)? Web 应 ...