js迭代器Iterator
标签:console iterator tor str self ring UNC obj val
使用 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
js迭代器Iterator
标签:console iterator tor str self ring UNC obj val
原文地址:https://www.cnblogs.com/alice-fee/p/14170147.html
评论