View generator-function-example-5.js
function* generatorWithEnd() {
yield 1;
yield 2;
yield 3;
yield 4;
yield 5;
}
let myIterator = generatorWithEnd();
View generator-function-example-4.js
myIterator.next().value // 2
myIterator.next().value // 3
myIterator.next().value // 4
myIterator.next().value // 5
myIterator.next().value // 6
myIterator.next().value // 7
myIterator.next().value // 8
myIterator.next().value // 9
myIterator.next().value // 10
View generator-function-example-3.js
myIterator.next()
/*
Object
done: false
value: 0
> __proto__: Object
*/
View generator-function-example-2.js
myIterator() // Uncaught TypeError: myGenerator is not a function
View generator-function-example-1.js
function* generatorFunction(){
var index = 0;
while(true)
yield index++;
}
let myIterator = generatorFunction();
console.log(myIterator)
View spread-operator-es6-5.js
var arr1 = [0, 1, 2];
var arr2 = [3, 4, 5];
arr1.push(...arr2); // 6
console.log(arr1); // [0, 1, 2, 3, 4, 5]
View spread-operator-es6-4.js
var arr1 = [0, 1, 2];
var arr2 = [3, 4, 5];
arr1.push(arr2); // 4
console.log(arr1) // [0, 1, 2, Array[3]]
View spread-operator-es6-3.js
function returnArgs() {
return arguments;
};
let array = [1, 2, 3, 4, 5];
returnArgs(...array); // [1, 2, 3, 4, 5]
View spread-operator-es6-2.js
function returnArgs() {
return arguments;
};
var array = [1, 2, 3, 4, 5];
returnArgs.apply(null, array); //[1, 2, 3, 4, 5]
View spread-operator-es6-1.js
function returnArgs() {
return arguments;
};
var array = [1, 2, 3, 4, 5];
returnArgs(array); // > [Array[5]