精华内容
下载资源
问答
  • <p>Acid falls down, gases spread up and down when possible. <p>Fire is a tiny bit more complex: - Raging fires spread up if there is no floor or if the floor is flammable - Any fire hanging in the air...
  • spread syntax spread syntax简单来说就是展开iterable obj,用法是**…iterableObj**,只能用在以下3个方面 iterable当作参数传入函数 function sum(x, y, z) { return x + y + z; } const numbers = [1, ...

    spread operator

    spread operator就是展开运算符,用来展开iterable obj,语法是 …iterableObj ,具体分为三种情况,调用函数时展开数组,在数组字面量中展开数组,在对象字面量中展开对象,只有这3种用法。

    函数调用时,展开数组

    function sum(x, y, z) {
    	return x + y + z;
    }
    
    const numbers = [1, 2, 3];
    console.log(sum(...numbers));//6
    console.log(sum.apply(null,numbers));//6
    

    可以看到如果参数是数组就不用apply转了,直接使用扩展运算符,语义更加简单明了。

    function Person(name,age){
    	console.log("%s,%s",name,age);
    }
    
    Person(...['jack',20]);  //jack,20
    

    为了加深理解,我们看看Babel编译后是什么样子

    function Person(name, age) {
    	console.log("%s,%s", name, age);
    }
    
    Person.apply(undefined, ['jack', 20]);
    

    可以看到本质上还是使用的apply,不过语法更简洁、更明了。

    在数组字面量中展开数组

    展开语法可以在数组字面量中,而且可以使用多次。

    var arr1 =[1,2];
    var arr2=[...arr1,3,...arr1];//[ 1, 2, 3, 1, 2 ]
    console.log(arr2);
    

    同样我们看一下babel编译后的代码

    var arr1 = [1, 2];
    var arr2 = [].concat(arr1, [3], arr1); //[ 1, 2, 3, 1, 2 ]
    console.log(arr2);
    

    在数组中展开数组时,相当于concat,那么以后能用到concat的地方可以用展开运算符了。
    ES5写法

    [].concat([1,2,3])
    

    ES6写法

    [...[1,2,3]]
    

    这里要注意到[...[1,2,3]] 相当于实现了clone,所以以前使用arr.slice()实现的clone,都可以使用展开运算符实现了。

    在对象字面量中展开对象

    在对象字面量中展开对象,且只能在对象字面中展开对象,实现展开属性、merge属性的功能;

    var p={name:"jack",age:12};
    var obj = {age:22,...p};
    console.log(obj);//{ age: 12, name: 'jack' }
    

    后记

    注意spread operator跟rest parameter非常相似,都是以…开头,但在功能上正好相反,spread operator用来展开参数,而rest parameter用来收集参数;

    展开全文
  • Spread / Rest 操作符

    2017-10-25 10:01:00
    Spread / Rest 操作符指的是...,具体是 Spread 还是 Rest 需要看上下文语境。 当被用于迭代器中时,它是一个 Spread 操作符:(参数为数组) function foo(x,y,z) { console.log(x,y,z); } let arr = [1,...

    Spread / Rest 操作符指的是 ...,具体是 Spread 还是 Rest 需要看上下文语境。

    当被用于迭代器中时,它是一个 Spread 操作符:(参数为数组)

    function foo(x,y,z) {
      console.log(x,y,z);
    }
    
    let arr = [1,2,3];
    foo(...arr); // 1 2 3

    当被用于函数传参时,是一个 Rest 操作符:(参数转化为数组)

    function foo(...args) {
      console.log(args);
    }
    foo( 1, 2, 3, 4, 5); // [1, 2, 3, 4, 5]

    转载于:https://www.cnblogs.com/wujiaqi/p/7727358.html

    展开全文
  • <div><h2>Abstruct <p>Adding global function is not reflected to Google Spread Sheet by clasp push to Apps Script bounded with Google Spread Sheet. <h2>Expected Behavior <p><img alt="img" src=...
  • (btw status page should show the full version as displayed in the browser: <code>25.10.xxx.y.z, instead of <code>10xxx</code>.. that is just my opinion)</p><p>该提问来源于开源项目:MicrosoftEdge...
  • ES6之后 — spread 或 rest 运算符 … ES6 引入了一个新的运算符 …,通常称为 spread 或 rest(展开或收集)运算符,取决于它在哪 / 如何使用。 用在数组(实际上是任何iterable)之前,把这个变量展开为各个独立...

    ES6 引入了一个新的运算符 …,通常称为 spread 或 rest(展开或收集)运算符,取决于它在哪 / 如何使用。

    1. 用在数组(实际上是任何iterable)之前,把这个变量展开为各个独立的值

      function foo (x, y, z) {
        console.log(x, y, z)
      }
      
      foo(...[1, 2, 3]) // 1 2 3
      // 替代之前ES6之前apply(..)的写法
      foo.apply(null, [1, 2, 3]) // 1 2 3
      
    2. 可以在上下文中用来展开 / 拓展一个值

      var a = [2, 3, 4]
      var b = [1, ...a, 5] // 基本上替代了concat(..)
      console.log(b) // [ 1, 2, 3, 4, 5 ]
      
    3. 收集剩余参数

    • 在函数声明中的 gather/rest 用法

      function rest (x, y, ...z) {
        console.log(x, y, z)
      }
      
      rest(1, 2, 3, 4, 5) // 1 2 [ 3, 4, 5 ]
      
      function rest_all (...rest) {
        // rest已经是一个收集所有参数,真正的数组,为类数组对象arguments提供了一个非常可靠的替代形式
        console.log(rest) // ...rest [ 1, 2, 3, 4, 5 ]
        console.log(...rest) // 展开 1 2 3 4 5
        rest.shift() // 使用数组方法
      
        // 替代ES6之前把arguments转换为一个真正的数组
        var args = Array.prototype.slice.call(arguments)
        console.log(args) // [ 1, 2, 3, 4, 5 ]
        console.log(arguments) // [Arguments] { '0': 1, '1': 2, '2': 3, '3': 4, '4': 5 }
      }
      
      rest_all(1, 2, 3, 4, 5)
      
    • 在解构赋值中 用法

      var a = [2, 3, 4]
      var [b, ...c] = a
      console.log(b, c) // 2 [ 3, 4 ] 收集剩余的值
      
    展开全文
  • In JS, we have object spread opreator: const x = { a: '1', b: '2' } const y = { c: '3', d: '4' } const z = { ...x, ...y } // z = {a: '1', b: '2', c: '3', d: '4'} ...

    In JS, we have object spread opreator:

    const x = {
         a: '1', b: '2'
    }
    
    const y = {
      c: '3', d: '4'
    }
    
    const z = {
       ...x,
       ...y
    }
    
    // z = {a: '1', b: '2', c: '3', d: '4'}

     

    In python we can do:

    x = {'a': 1, 'b': 2}
    y = {'b': 3, 'c': 4}
    
    z = {**x, **y}
    
    // z= {'c': 4, 'a': 1, 'b': 3}

     

    转载于:https://www.cnblogs.com/Answer1215/p/7597442.html

    展开全文
  • <p><code>vue.esm.js:566 TypeError: Invalid attempt to spread non-iterable instance at vue-good-table.es.js:81 at v (vue-good-table.es.js:35) at vue-good-table.es.js:1667 at s (index.js:35) at e....
  • 一、扩展运算符(spread)  场景:使用在数组之前。  作用:将一个数组转为用逗号分隔的参数序列  举例1:数组之前 function foo(x, y, z){ console.log(x, y, z) } foo.apply(null, [1, 2, 3]) //在ES6...
  • 前一篇文章讲了Spread操作符在函数参数中的用法,这篇简单讲一下Spread操作符在数组元素中的应用。直接看代码吧: [1, ...[2,3], 4]//[1, 2, 3, 4] let x = ['a', 'b']; let y = ['c']; let z = ['d', 'e']; let ...
  • @[Spread, Reast, …...function foo (x, y, z) { … } let arr = [1, 2, 3] foo (…arr) 对象的 spread 操作,这里写一个对象的复制操作 let obj = { name: ‘张三’, age: 20, sex: ‘男’ } let temp = (…obj)...
  • 展开语法,属于es6的新语法,可以在函数调用、数组构造...function sum(x, y, z) { return x + y + z; } const numbers = [1, 2, 3]; sum(...numbers); 2、构造数组,展开数组 const arr1 = [3,4,5]; const arr...
  • <p>iOS9 设备上的 Safari 始终报 “Invalid attempt to spread non-iterable instance” 错误 调试后发现 <code>_arrayWithoutHoles</code> 方法中的 <code>Array.isArray()</code> 返回 false,移除这个判断...
  • def myfunc(x, y, z): print(x, y, z) tuple_vec = (1, 0, 1) dict_vec = {'x': 1, 'y': 0, 'z': 1} >>> myfunc(*tuple_vec) 1, 0, 1 >>> myfunc(**dict_vec) 1, 0, 1 转载...
  • 这节学习ES6中的spread/rest(展开或收集运算符)及默认参数值。 第一部分:扩展运算符(spread)  场景:使用在数组之前。  作用:将一个数组转为用逗号分隔的参数序列  举例1:数组之前 function foo(x, y, ...
  • In my opinion, real use cases are closer to non blocking asynchronous code spread into multiple files. That is where you will see a difference anyway, especially for runners which use parallelization...
  • Oracle 11G OCP 1Z0-053 538

    2014-10-29 07:16:29
    (538)Which type of database file is spread across all disks in a disk group? A. All types of files are spread ...
  • Oracle OCP 1Z0 053 Q538(ASM)

    2016-04-06 13:59:14
    538.Which type of database file is spread across all disks in a disk group? A. All types of files are spread acro...
  • Is the random offset happening within a block for a rank or will each I/0 of a rank be randomly spread across an entire segment? <p>Cheers, Bjoern</p><p>该提问来源于开源项目:hpc/ior</p></div>
  • OCP 1Z0 052 24

    2014-06-10 16:07:18
    24. Which two statements correctly describe the relation between a data file and the logical database  structures? (Choose two.)  ...A.An extent cannot spread across data files.  B.A segment can
  • OCP-1Z0-053-V13.02-538题

    千次阅读 2014-02-21 09:33:36
    538.Which type of database file is spread across all disks in a disk group? A. All types of files are spread across all disks in the disk group. B. Datafiles C. Redo log files D. Archived redo log
  • LTE from A to Z

    2010-05-11 15:41:47
    LTE from A-Z Technology and Concepts of the 4G 3GPP Standard Table of Content Principles and Motivation of LTE............................................1 1.1 Mobile Radio: Comparison between 3G ...
  • 1-4 Describe the spread mechanism used in UMTS, and please draw the power spectrum before and after spreading. 1-5 Please describe the functionalities of rake receiver? 2-1 Explain (draw) the 4 TCP-IP...
  • OCP-1Z0-052-V8.02-24题

    万次阅读 2013-11-15 14:53:04
    24. Which two statements correctly describe the relation between a data file and the logical database structures?...A.An extent cannot spread across data files. B.A segment cannot sprea
  • LTE from A to Z (part1 of 3)

    2010-05-11 15:38:52
    LTE from A-Z Technology and Concepts of the 4G 3GPP Standard Table of Content Principles and Motivation of LTE............................................1 1.1 Mobile Radio: Comparison between 3G ...

空空如也

空空如也

1 2 3 4 5 ... 11
收藏数 207
精华内容 82
关键字:

spreadz