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