javascript 别名_JavaScript解构别名

javascript 别名

Destructuring in JavaScript has totally changed the way JavaScript is written these days;  code is more concise to write but but, from a visual standpoint, the syntax of the language has changed so much.  Any good developer knows, however, that change is the constant we live in.

如今,JavaScript的解构已完全改变了JavaScript的编写方式。 代码编写起来更加简洁,但是从视觉上来说,该语言的语法已经发生了很大变化。 但是,任何优秀的开发人员都知道,变化是我们赖以生存的不变。

The basic idea behind destructuring in object literals is as follows:

对象文字解构背后的基本思想如下:


const obj = { x: 1 };

// Grabs obj.x as { x }
const { x } = obj;


There are cases where you want the destructured variable to have a different name than the property name; in that case, you'll use a : newName to specify a name for the variable:

在某些情况下,您希望结构化变量的名称与属性名称不同。 在这种情况下,您将使用: newName为变量指定名称:


// Grabs obj.x as as { otherName }
const { x: otherName } = obj;


The syntax for specifying an alternate destructured name for an object property is simple and needed.  Destructuring had the capability to confuse developers, especially array destructuring and function argument destructuring, but this alias syntax is a simple trick to keep in your locker!

为对象属性指定备用的非结构化名称的语法很简单,也很需要。 解构具有混淆开发人员的能力,尤其是数组解构函数参数解构 ,但是此别名语法是保存在更衣柜中的简单技巧!

翻译自: https://davidwalsh.name/destructuring-alias

javascript 别名

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值