'use strict';
let range = {
from: 1,
to: 5,
[Symbol.iterator]() {
return {
next() {
if (this.from <= this.to) {
return {
done: false,
value: this.from++
};
} else {
return {
done: true
};
}
}
}
},
};
for (let num of range) {
alert(num); // Не выводится 1, 2, 3, 4, 5
}