Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #38469

Re: let syntax

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: let syntax
Date 2020-06-16 21:23 +0200
Organization PointedEars Software (PES)
Message-ID <7793047.T7Z3S40VBb@PointedEars.de> (permalink)
References <Gt-dnYgvE8ieWHvDnZ2dnUU7-QnNnZ2d@westnet.com.au> <20200614212651.513dc927@james.kirk.invalid> <sa2dndANOaaDd3vDnZ2dnUU7-IfNnZ2d@westnet.com.au>

Show all headers | View raw


Andrew Poulos wrote:

> On 15/06/2020 11:26 am, James Kirk wrote:
>> Andrew Poulos <ap_prog@hotmail.com> wrote:
>>> function move(e) {
>>>    let { target:el } = e;
>> 
>>>    if (el.nextElementSibling){
>>>      el.parentNode.appendChild(el);
>>>    }
>>> }
>>> […]
>> 
>>> I don't understand how the first line in "move" works. It seems that
>>>    let { target:el } = e;
>>> is equivalent to
>>>    let el = e.target;
>> 
>>> but how?
>> 
>> Destructuring assignment
>> 
>> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
> 
> Cool, a whole new area I knew nothing about!
> 
> In this case, why would choose one rather than the other?

DRY.  If you wanted to extract other properties, you just have to expand the 
destructuring assignment instead of writing one more assignment and 
duplicating the object reference on the right-hand side of the “=”.

Personally I find this particular syntax more confusing than helpful because 
what is being assigned *to* is now unexpectedly on the *right*-hand side of 
what can reasonably construed to be an assignment (“…: …”).

Compare: <https://github.com/airbnb/javascript#destructuring>

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

let syntax Andrew Poulos <ap_prog@hotmail.com> - 2020-06-15 10:46 +1000
  Re: let syntax James Kirk <noneya.invalid@gmail.com> - 2020-06-14 21:26 -0400
    Re: let syntax Andrew Poulos <ap_prog@hotmail.com> - 2020-06-15 13:25 +1000
      Re: let syntax James Kirk <noneya.invalid@gmail.com> - 2020-06-15 00:06 -0400
      Re: let syntax Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-06-16 21:23 +0200
        Re: let syntax Andrew Poulos <ap_prog@hotmail.com> - 2020-06-17 10:24 +1000
        Re: let syntax Julio Di Egidio <julio@diegidio.name> - 2020-06-16 21:19 -0700

csiph-web