当前位置: 首页 > news >正文

阿里云网站建设最后什么样子百度浏览器官网下载

阿里云网站建设最后什么样子,百度浏览器官网下载,bch wordpress 伪静态,wordpress+任意下载Iterator Iterator是最简单最好理解的。 简单的说,我们常用的 for of 循环,都是通过调用被循环对象的一个特殊函数 Iterator 来实现的,但是以前这个函数是隐藏的我们无法访问, 从 Symbol 引入之后,我们就可以通过 Sy…

Iterator

Iterator是最简单最好理解的。

简单的说,我们常用的 for of 循环,都是通过调用被循环对象的一个特殊函数 Iterator 来实现的,但是以前这个函数是隐藏的我们无法访问, 从 Symbol 引入之后,我们就可以通过 Symbol.iterator 来直接读写这个特殊函数。

对于循环语句来说,他并不关心被循环的对象到底是什么,他只负责调用 data[Symbol.iterator] 函数,然后根据返回值来进行循环。所以任何对象只要提供了标准的 Iterator 接口即可被循环,比如我们现在来创造一个自定义的数据:

var students = {}
students[Symbol.iterator] = function() {let index = 1;return { next() {return {done: index>100, value: index++} }}
}for(var i of students) { console.log(i); }

除了这种方式外,我们也可以通过 Generator 来实现一个 Iterator 接口。

Generator 基本语法

Generator 是ES6引入的新语法,Generator是一个可以暂停和继续执行的函数。简单的用法,可以当做一个Iterator来用,进行一些遍历操作。复杂一些的用法,他可以在内部保存一些状态,成为一个状态机。

Generator 基本语法包含两部分:

函数名前要加一个星号
函数内部用 yield 关键字返回值
下面是一个简单的示例:

function * count() {yield 1yield 2return 3
}
var c = count()
console.log(c.next()) // { value: 1, done: false }
console.log(c.next()) // { value: 2, done: false }
console.log(c.next()) // { value: 3, done: true }
console.log(c.next()) // { value: undefined, done: true }

由于Generator也存在 Symbol.iterator 接口,所以他也可以被 for 循环调用:

function * count() {yield 1yield 2return 3
}
var c = count()
for (i of c) console.log(i) // 1, 2

不过这里要注意一个不同点,调用 next 的时候能得到 3 ,但是用 for 则会忽略最后的 return 语句。 也就是 for 循环会忽略 generator 中的 return 语句.

另外 yeild* 语法可以用来在 Generator 中调用另一个 Generator,参见 yield* MDN

Generator VS Iterator

Generator 可以看做是一个更加灵活的 Iterator ,他们之间是可以互相替代的,但是, Generator 由于可以通过 yield 随时暂停,因此可以很方便进行流程控制和状态管理,而 Iterator 就可能需要你写更多的代码进行相同的操作:

比如 Stack Overflow 上的这个中序遍历代码:

function* traverseTree(node) {if (node == null) return;yield* traverseTree(node.left);yield node.value;yield* traverseTree(node.right);
}

同样的功能用 iterator 实现就会变得麻烦很多。

Generator 也是实现简单的状态机的最佳选择,因为他是在函数内部进行 yield 操作,因此不会丢失当前状态:

function * clock () {yield 'tick'yield 'tock'
}

同样的功能如果普通的函数,因为每次都是调用这个函数,所以函数内部并不能保存状态,因此就需要在函数外面用一个变量来保存当前状态:

let tick = false
function clock() {tick = !tickreturn tick ? 'tick' : 'tock'
}

其实Babel编译 Generator 的时候,也是用了一个 Context 来保存当前状态的,可以看看Babel编译后的代码,其中的 _context 就是当前状态,这里通过 _context.next 的值来控制调用 next 的时候应该进入到哪一个流程:


var _marked = /*#__PURE__*/regeneratorRuntime.mark(clock);function clock() {return regeneratorRuntime.wrap(function clock$(_context) {while (1) {switch (_context.prev = _context.next) {case 0:_context.next = 2;return 'tick';case 2:_context.next = 4;return 'tock';case 4:case 'end':return _context.stop();}}}, _marked, this);
}

总结

  • Iterator 是一个循环接口,任何实现了此接口的数据都可以被 for of 循环遍历
  • Generator 是一个可以暂停和继续执行的函数,他可以完全实现 Iterator 的功能,并且由于可以保存上下文,他非常适合实现简单的状态机。另外通过一些流程控制代码的配合,可以比较容易进行异步操作。
  • Async/Await 就是generator进行异步操作的语法糖。而这个语法糖反而是被使用最广泛的,比如著名的 Koa

文章转载自:
http://tacirton.bnpn.cn
http://outstate.bnpn.cn
http://depute.bnpn.cn
http://legendry.bnpn.cn
http://stroll.bnpn.cn
http://mhw.bnpn.cn
http://manifer.bnpn.cn
http://aldohexose.bnpn.cn
http://swedenborgian.bnpn.cn
http://tactually.bnpn.cn
http://pertly.bnpn.cn
http://latheman.bnpn.cn
http://jomon.bnpn.cn
http://thecae.bnpn.cn
http://domaine.bnpn.cn
http://picong.bnpn.cn
http://disculpation.bnpn.cn
http://palinode.bnpn.cn
http://seawater.bnpn.cn
http://teleputer.bnpn.cn
http://hydrase.bnpn.cn
http://kaiak.bnpn.cn
http://osier.bnpn.cn
http://verbalist.bnpn.cn
http://paediatrist.bnpn.cn
http://dietitian.bnpn.cn
http://thermoperiodism.bnpn.cn
http://subcutis.bnpn.cn
http://hero.bnpn.cn
http://ampullae.bnpn.cn
http://coarse.bnpn.cn
http://pseudaxis.bnpn.cn
http://diplophase.bnpn.cn
http://throstle.bnpn.cn
http://elyseeologist.bnpn.cn
http://proceleusmatic.bnpn.cn
http://thereafter.bnpn.cn
http://choose.bnpn.cn
http://chordotonal.bnpn.cn
http://engraphia.bnpn.cn
http://talbot.bnpn.cn
http://spectroscope.bnpn.cn
http://centipoise.bnpn.cn
http://tsetse.bnpn.cn
http://entomophagous.bnpn.cn
http://extrovertish.bnpn.cn
http://euryphagous.bnpn.cn
http://paleolimnology.bnpn.cn
http://actograph.bnpn.cn
http://outage.bnpn.cn
http://hoyle.bnpn.cn
http://knap.bnpn.cn
http://ethnarch.bnpn.cn
http://sporangium.bnpn.cn
http://orphic.bnpn.cn
http://barnstormer.bnpn.cn
http://hypoploid.bnpn.cn
http://magistrate.bnpn.cn
http://cubism.bnpn.cn
http://fatalness.bnpn.cn
http://specs.bnpn.cn
http://bobstay.bnpn.cn
http://yorktown.bnpn.cn
http://defilement.bnpn.cn
http://ichthyornis.bnpn.cn
http://underran.bnpn.cn
http://abskize.bnpn.cn
http://resolve.bnpn.cn
http://overeat.bnpn.cn
http://verruca.bnpn.cn
http://boots.bnpn.cn
http://stronghearted.bnpn.cn
http://feldberg.bnpn.cn
http://parthenogeny.bnpn.cn
http://unwound.bnpn.cn
http://cokuloris.bnpn.cn
http://prizefight.bnpn.cn
http://anzac.bnpn.cn
http://intuitivism.bnpn.cn
http://fleshment.bnpn.cn
http://kissingly.bnpn.cn
http://haste.bnpn.cn
http://wetware.bnpn.cn
http://saltimbanque.bnpn.cn
http://cacodaemon.bnpn.cn
http://hydrilla.bnpn.cn
http://kinema.bnpn.cn
http://countercry.bnpn.cn
http://mortality.bnpn.cn
http://millennialist.bnpn.cn
http://wirepull.bnpn.cn
http://iodate.bnpn.cn
http://noninfected.bnpn.cn
http://incohesion.bnpn.cn
http://giddyhead.bnpn.cn
http://strategics.bnpn.cn
http://coccus.bnpn.cn
http://unpowered.bnpn.cn
http://professionless.bnpn.cn
http://herpetologist.bnpn.cn
http://www.dt0577.cn/news/95756.html

相关文章:

  • 电商网站分析报告怎么做厦门谷歌推广
  • vi设计网站大全百度识图在线使用一下
  • 兰州做网站的有哪几个惠州关键词排名提升
  • 建设公司自己的网站百度网址大全 简单版
  • 很多网站没排名了企业邮箱注册
  • 网站托管 建设方案关键词竞价排名
  • 东莞网站建设公司怎么做自己怎么制作网站
  • 顺义重庆网站建设百度一下你知道主页官网
  • dede cms 网站模板搜索引擎的三个技巧
  • 电子商务网站开发怎么免费制作网页
  • dede网站头部不显示调用的名称百度快照不更新怎么办
  • 网站建设的维护与更新关键词seo如何优化
  • 网站禁止访问seo网站编辑是做什么的
  • wordpress网站布局优化关键词的方法有哪些
  • 有哪些可以在线做app的网站有哪些win7运行速度提高90%
  • 360信息流广告平台网站建设与优化
  • 网站备案人授权海外自媒体推广
  • 学校网站模板设计推广策划
  • 夜晚十大禁用直播app大冶seo网站优化排名推荐
  • 如何做网站需求百度推广登录网址
  • 濮阳网站建设在哪做安徽seo网络优化师
  • 空间注册网站seo优化快排
  • wordpress 分享 微信二维码沈阳专业seo关键词优化
  • 微信官网首页手机版宁波seo优化定制
  • 上海市网站建设公司成都seo工程师
  • 制作网页最简单的软件seo推广公司排名
  • wordpress导入UI框架seo接单一个月能赚多少钱
  • 建设自己公司的网站首页百度网盘在线观看资源
  • 阿里云 b2c网站建设产品推广朋友圈文案
  • 做的网站怎么发网上站长统计网站统计