I am currently experimenting with an iterable expression of destructuring, and I wonder why a particular method does not work. Maybe you can help me.
For example, this works:
var x, y, myIterable = [];
myIterable[Symbol.iterator] = function* () {
var count = 0;
while(count < 2){
yield count++;
}
};
var myArray = Array.from(myIterable);
console.log(([x,y] = myArray) === myArray);
But if I try it like this, it will return false, can you explain why?
var x, y, myIterable = [];
myIterable[Symbol.iterator] = function* () {
var count = 0;
while(count < 2){
yield count++;
}
};
var myArray = Array.from(myIterable);
[x, y] = myArray;
console.log([x,y] === myArray);
source
share