Destructuring for Array-like objects

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Destructuring for Array-like objects

Sultan
Afford array destructuring to Array-like objects.

const [a, b] = {0: a, 1: b, length: 2}



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Destructuring for Array-like objects

Ranando King
Why is that any different or better than

const [a, b] = [a, b]

?

On Tue, Mar 19, 2019 at 7:59 PM Sultan <[hidden email]> wrote:
Afford array destructuring to Array-like objects.

const [a, b] = {0: a, 1: b, length: 2}


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Destructuring for Array-like objects

Frederick Stark
In reply to this post by Sultan
This already works with an iterator, because array destructuring uses the iterator protocol

const [a, b] = {
  0: "ayy",
  1: "bee",
  length: 2,
  *[Symbol.iterator]() {
      let i = 0;
      while (i < this.length) {
          yield this[i]
          i++
      }
  },
};


On Mar 20 2019, at 11:59 am, Sultan <[hidden email]> wrote:
Afford array destructuring to Array-like objects.

const [a, b] = {0: a, 1: b, length: 2}


_______________________________________________
es-discuss mailing list
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Destructuring for Array-like objects

Jordan Harband
`const [a, b] = Array.from(anyArraylikeObject);`

On Tue, Mar 19, 2019 at 7:22 PM Frederick Stark <[hidden email]> wrote:
This already works with an iterator, because array destructuring uses the iterator protocol

const [a, b] = {
  0: "ayy",
  1: "bee",
  length: 2,
  *[Symbol.iterator]() {
      let i = 0;
      while (i < this.length) {
          yield this[i]
          i++
      }
  },
};


On Mar 20 2019, at 11:59 am, Sultan <[hidden email]> wrote:
Afford array destructuring to Array-like objects.

const [a, b] = {0: a, 1: b, length: 2}


_______________________________________________
es-discuss mailing list
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Destructuring for Array-like objects

guest271314
In reply to this post by Sultan
    
If gather the expected result correctly object destructuring can be used

    const {0: a, 1: b} = {0: a, 1: b, length: 2}

On Wed, Mar 20, 2019 at 12:59 AM Sultan <[hidden email]> wrote:
Afford array destructuring to Array-like objects.

const [a, b] = {0: a, 1: b, length: 2}


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Destructuring for Array-like objects

J Decker


On Fri, Mar 22, 2019 at 10:32 AM guest271314 <[hidden email]> wrote:
    
If gather the expected result correctly object destructuring can be used

    const {0: a, 1: b} = {0: a, 1: b, length: 2}
 
var a = "testa", b="testb"; const {0: c, 1: d} = {0: a, 1: b, length: 2}
results in a const 'c' and const 'd' created with the vlaues of a and b.

shouldn't it have created a variable '0' and '1' ? 

On Wed, Mar 20, 2019 at 12:59 AM Sultan <[hidden email]> wrote:
Afford array destructuring to Array-like objects.

const [a, b] = {0: a, 1: b, length: 2}


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Destructuring for Array-like objects

guest271314
shouldn't it have created a variable '0' and '1' ? 


On Fri, Mar 22, 2019 at 6:38 PM J Decker <[hidden email]> wrote:


On Fri, Mar 22, 2019 at 10:32 AM guest271314 <[hidden email]> wrote:
    
If gather the expected result correctly object destructuring can be used

    const {0: a, 1: b} = {0: a, 1: b, length: 2}
 
var a = "testa", b="testb"; const {0: c, 1: d} = {0: a, 1: b, length: 2}
results in a const 'c' and const 'd' created with the vlaues of a and b.

shouldn't it have created a variable '0' and '1' ? 

On Wed, Mar 20, 2019 at 12:59 AM Sultan <[hidden email]> wrote:
Afford array destructuring to Array-like objects.

const [a, b] = {0: a, 1: b, length: 2}


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss