......运营商的名称是什么? [英] What is the name of the ... operator?

查看:196
本文介绍了......运营商的名称是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

... 运算符是spread运算符,它具有两种不同的语义,具体取决于其词法位置(参数位置与解构赋值,数组,参数位置等) )?

Is the ... operator the "spread" operator that has a two different semantics depending on its lexical position (parameter position vs destructuring assignment, Arrays, argument position etc)?

或者它有两个名称spread和rest?

Or does it have two names "spread" and "rest"?

推荐答案

根据使用情况,它是同一个具有不同名称的运算符。

It's the same operator with different names based on the usage.

休息属性

Rest属性收集剩余的自身可枚举属性键,这些键尚未被解构模式选中。这些键及其值将复制到新对象上。

Rest properties collect the remaining own enumerable property keys that are not already picked off by the destructuring pattern. Those keys and their values are copied onto a new object.

let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
x; // 1
y; // 2
z; // { a: 3, b: 4 }

点差属性

对象初始值设定项中的Spread属性将自己的可枚举属性从提供的对象复制到新创建的对象上。

Spread properties in object initializers copies own enumerable properties from a provided object onto the newly created object.

let n = { x, y, ...z };
n; // { x: 1, y: 2, a: 3, b: 4 }

更多......

这篇关于......运营商的名称是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆