js迭代器Iterator
使用 yeild 异步编程
function * abc () {
var a = yield API.getGeneralData({ areacode: self.valueAreaVal, year: self.valueDate });
console.log(a);
var b = yield API.getObjectTypes({ areacode: self.valueAreaVal, year: self.valueDate });
console.log(b);
var res = [a, b];
return res;
}
可以用他来遍历String,Array,Map,Set。
function* entries(obj) { for (let key of Object.keys(obj)) { yield [key, obj[key]]; } } for (let [key, value] of entries(obj)) { console.log(key, "->", value); }
// a -> 1 // b -> 2 // c -> 3