From ec9debe80f128aaa62d1d4b7ee2ae123231bfe39 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Thu, 26 Oct 2017 14:20:56 +0800 Subject: [PATCH] es6: Move reassigning keys to its own example --- es6.md | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/es6.md b/es6.md index 7bf12fb52..1b9bc7f95 100644 --- a/es6.md +++ b/es6.md @@ -223,23 +223,30 @@ Default values can be assigned while destructuring arrays or objects. function greet({ name, greeting }) { console.log(`${greeting}, ${name}!`) } - -function add([ num1, num2 ]) { - console.log(`result: ${num1 + num2}`) -} - -function printCoordinates({ coordx: x, coordy: y }) { - console.log(`x: ${x}, y: ${y}`); -} ``` {: data-line="1"} ```js greet({ name: 'Larry', greeting: 'Ahoy' }) -add([2,4]) -printCoordinates({ coordx: 25, coordy: 90 }) ``` +Destructuring of objects and arrays can be also be done in function arguments. + +### Reassigning keys + +```js +function printCoordinates({ left: x, top: y }) { + console.log(`x: ${x}, y: ${y}`) +} +``` +{: data-line="1"} + +```js +printCoordinates({ left: 25, top: 90 }) +``` + +This example assigns `x` to the value of the `left` key. + ### Loops ```js