Skip to main content
183 votes
14 answers
82k views

How one can write a function, which takes only few attributes in most-compact way in ES6? I've came up with solution using destructuring + simplified object literal, but I don't like that list of ...
kirilloid's user avatar
  • 14.4k
20 votes
3 answers
7k views

I have been reading about Destructuring assignment introduced in ES6. What is the purpose of this syntax, why was it introduced, and what are some examples of how it might be used in practice?
Code Maniac's user avatar
  • 37.9k
12 votes
1 answer
2k views

If I want to call a function like this: moo({ a: 4 }); Normally I'd have to phrase my function definition like this: function moo(myArgObj) { print(myArgObj.a); } But this awesome syntax is ...
Verdagon's user avatar
  • 2,650
36 votes
4 answers
15k views

For a project, a developer sent us a JS file with code similar to this: var myList = [ 1, 2, 3 ]; var a, b, c; [ a, b, c ] = myList; It works in Opera 10.30, and Firefox 3.6.x, but it’s not okay for ...
napolux's user avatar
  • 16.2k
29 votes
5 answers
6k views

Is there a way to retain the name of a destructured function argument? I.e., the name of the root object? In ES5, I might do this (using inheritance as a metaphor to make the point): // ES5: var ...
jbx's user avatar
  • 443
191 votes
17 answers
102k views

For example, if I have two objects: var foo = { x: "bar", y: "baz" } and var oof = {} and I wanted to transfer the x and y values from foo to oof. Is there a way to do that ...
tnrich's user avatar
  • 8,730
13 votes
4 answers
1k views

Can anyone explain, why the following happens with ES6 array destructuring? let a, b, c [a, b] = ['A', 'B'] [b, c] = ['BB', 'C'] console.log(`a=${a} b=${b} c=${c}`) Expected: a=A b=BB c=C ...
ronkot's user avatar
  • 6,477
151 votes
4 answers
34k views

Not sure if this is a Mozilla-specific JS syntax, but I often found variables being declared this way, for example, in add-on SDK docs: var { Hotkey } = require("sdk/hotkeys"); and in various chrome ...
timdream's user avatar
  • 5,922
52 votes
5 answers
17k views

I'd like to do something like this: const vegetableColors = {corn: 'yellow', peas: 'green'}; const {*} = vegetableColors; console.log(corn);// yellow console.log(peas);// green I can't seem to find ...
Resist Design's user avatar
36 votes
1 answer
13k views

How can I rename the target during object destructing? const b = 6; const test = { a: 1, b: 2 }; const {a, b as c} = test; // <-- `as` does not seem to be valid in ES6/ES2015 // a === 1 // b === 6 ...
Jack Allan's user avatar
  • 15.1k
99 votes
3 answers
34k views

As object keys are strings, they can contain any kind of characters and special characters. I recently stumbled upon an object which I receive from an API call. This object has '-' in it's key names. ...
larrydahooster's user avatar
374 votes
8 answers
242k views

This const { foo: IFoo[] } = bar; and this const { foo: Array<IFoo> } = bar; will reasonably cause an error. And this const { foo: TFoo } = bar; will just destructure TFoo property. How can ...
Estus Flask's user avatar
187 votes
3 answers
122k views

const a = { b: { c: 'Hi!' } }; const { b: { c } } = a; Is it possible rename b in this case? I want get c and also rename b.
leusrox's user avatar
  • 2,485
172 votes
19 answers
171k views

In CoffeeScript, this is straightforward: coffee> a = ['a', 'b', 'program'] [ 'a', 'b', 'program' ] coffee> [_..., b] = a [ 'a', 'b', 'program' ] coffee> b 'program' Does ES6 allow for ...
George Simms's user avatar
  • 4,080
78 votes
3 answers
46k views

This recent video claims that EMCAScript 6 destructuring is already partially implemented in Node.JS. I have tried various examples (using v0.10.12 and the --harmony flag), such as var [a, b] = [1, 2]...
Randomblue's user avatar
  • 117k

15 30 50 per page
1
2 3 4 5
13