扩展运算符...

也可以用扩展运算符...来将一个对象展开。

<template is="objectCombine" data="{{...obj1, ...obj2, e: 5}}">template> 
Page({
  data: {
    obj1: {
      a: 1,
      b: 2 }, obj2: { c: 3, d: 4 } } }) 

最终组合成的对象是 {a: 1, b: 2, c: 3, d: 4, e: 5}。

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Spread_syntax

function sum(x, y, z) {
return x + y + z;
}

const numbers = [1, 2, 3];

console.log(sum(...numbers));
// expected output: 6

console.log(sum.apply(null, numbers));
// expected output: 6

转载于:https://www.cnblogs.com/liuqiyun/p/11120730.html

你可能感兴趣的:(扩展运算符...)