标签:class new define 统一 rip -- 需要 data func
const arr = [1, 2, 3]; function iterator(arr){ let index = 0; return { next: function (){ return index < arr.length ? {value: arr[index++], done: false} : {value: undefined, done: true}; } } } const it = iterator(arr); console.log(it.next()); console.log(it.next()); console.log(it.next()); console.log(it.next());
const arr = [1, 2, 3]; const set = new Set([‘a‘, ‘b‘, ‘c‘]); const map = new Map([[‘a‘, 1]]); const itArr = arr[Symbol.iterator](); const itSet = set[Symbol.iterator](); const itMap = map[Symbol.iterator](); console.log(itArr); console.log(itSet); console.log(itMap); console.log(itSet.next()); console.log(itSet.next()); console.log(itSet.next()); console.log(itSet.next()); const obj = {}; console.log(obj[Symbol.iterator]);
const set = new Set([‘a‘, ‘b‘, ‘c‘]); let [x, y] = set;
let str = ‘leiliangqing‘;
let arrStr = [...str];
const ofArr = [1, 2, 3, 4]; for(let i of ofArr){ console.log(i); } const m = new Map(); m.set(‘a‘, 1).set(‘b‘, 2).set(‘c‘, 3); // for(let data of m){ // console.log(data); // } for(let [key, value] of m){ console.log(key, value); }
标签:class new define 统一 rip -- 需要 data func
原文地址:http://www.cnblogs.com/nankeyimeng/p/7197806.html