3

Here's a contrived example.

I can do this with an instance an array:

function* cut () {
  for (let slice = 0; slice < 3; slice++) yield '';
}

const cake = [''];
cake[Symbol.iterator] = cut;
const slices = [...cake];
//=> ['', '', '']

But I cannot do the same with a string:

const cake = '';
cake[Symbol.iterator] = cut;
const slices = [...cake];
//=> ['']

Why?

customcommander
  • 17,580
  • 5
  • 58
  • 84

0 Answers0