Eteration - 解释和示例 [英] Eteration - explanation and example

查看:44
本文介绍了Eteration - 解释和示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释一下什么是迭代并举例说明?

Can someone explain what exactly is Eteration and show an example?

来源:长时间运行的任务 Douglas Crockford 的 YUI 博客

source: Long running tasks YUI blog by Douglas Crockford

推荐答案

一开始,我以为这只是迭代的一个错字,因为在网上搜索迭代没有结果效果显着.

Initially, I thought it was just a typo of iteration, as searching online for eteration yields no significant results.

但是,然后,我遇到了参考资料,其中指出这个词是克罗克福德本人在他的一次演讲中创造的.
在网上,我唯一能找到解释的地方是在他的页面上,The Factorial Tutorial,一篇文章,在第 2 条中,作为对代码示例的注释,他指出:

But, then, I came across references that state that the term is coined by Crockford himself, in one of his talks.
Online, the only place where I could find an explanation is on his page, in The Factorial Tutorial, an article where, in Act 2, as a comment to a code sample, he states:

Act 2a:消息迭代(eteration)

Act 2a: message iteration (eteration)

这似乎是一对相关术语的一部分,作为他的下一个代码示例,在不使用堆栈的情况下执行递归,包含该对的另一个成员:

This seems to be part of a related pair of terms, as his next code sample, that performs recursion without using a stack, contains the other member of the pair:

Act 2b:消息递归(ecursion)

Act 2b: message recursion (ecursion)

因此,eterationecursion 似乎是 Crockford 自己发明和定义的术语,用于指代 E 编程语言,基于 Java 为编写分布式应用程序的开发人员设计.

So, it seems that eteration and ecursion are terms invented and defined by Crockford himself to refer to message iteration and recursion in the context of the E Programming Language, designed on top of Java for developers who write distributed applications.

该语言被称为 E 的事实可能是为其特定迭代和递归风格赋予所选术语(**e***teration* 和 **e***cursion*).

The fact that the language is called E is perhaps a reason to give its specific iteration and recursion flavors the chosen terminology (**e***teration* and **e***cursion*).

如果是关于 Javascript 的上下文,Crockford 在演讲中解释了术语迭代Crockford on JavaScript -- 场景 6:Loopage,从 30:40 开始:

If the context of Javascript, Crockford explains the term eteration as part of the talk Crockford on JavaScript -- Scene 6: Loopage, starting from minute 30:40:

Eteration 意味着将任务分解为多个回合,以便在每个回合中迭代,而不是通过传统的循环,在底部我们调用 setTimeOut 的循环,传递给它一个函数,导致我们做下一次迭代.这意味着转弯将是短——转牌只需要一次迭代——我们可以这样做我们想要的多次迭代,而不是锁定事件循环.

Eteration means to break a task into multiple turns so that on each eteration, instead of going through a conventional loop, at the bottom of the loop we call setTimeOut, passing it a function which causes us to do the next eteration. That means that the turns are going to be short — the turn's only as long as one eteration – and we can do as many eterations as we want and not lock up the event loop.

结果是,不是一个紧密的循环,如果时间太长就会阻塞接口,迭代会安排循环的每一步,在一个链中,只阻塞接口,而实际步骤执行,而不是在步骤之间.这使得可以在与界面相同的线程中执行长时间运行的任务(Javascript 是单线程的),同时保持应用程序响应能力.

The result is that, instead of a tight loop, blocking the interface if it takes too long, the eteration schedules each step of the loop, in a chain that only blocks the interface while the actual step executes, not between steps. This makes it possible to perform long-running tasks in the same thread as the interface (Javascript is single-threaded), while maintaining application responsiveness.

查看质量更高的完整演讲,并附有全文成绩单此处.

Check out the full talk in much better quality and accompanied by a full-text transcript here.

此外,有关如何实施此类技术的参考,请考虑以下场景:

Also, for a reference on how such a technique might be implemented, consider the following scenario:

<html>
 <head>
  <script type="text/javascript">
   function testFeedback()
   {
      var feedbackDiv = document.getElementById("feedbackDiv");

      feedbackDiv.innerHTML += "The Interface is Still Responsive!</br>";
   }

   var currentNumber = 0;
   var loopStepDelay = 30;

   function performLoopStep()
   {
     var numbersDiv = document.getElementById("numbersDiv");
     numbersDiv.innerHTML = currentNumber++;
     setTimeout("performLoopStep()", loopStepDelay);
   }
   setTimeout("performLoopStep()", loopStepDelay);
  </script>
 </head>
 <body>
  <div id="numbersDiv"></div>
  </br>
  </br>
  <div id="feedbackDiv"></div>
  </br>
  </br>
  <button onClick="testFeedback()">Try Me</button>
 <body>
</html>

有两个 div,一个显示正在进行的迭代的索引,另一个在每个 Try Me 上附加文本 The Interface is Still Responsive! 按钮按下.从代码中可以看出,迭代步骤是由 setTimeout 安排的,间隔一定的时间间隔,允许用户交互发生和处理.因此,当用户单击按钮并触发第二个 div 的更新时,迭代步骤将继续运行,保持页面的响应能力,同时执行它必须执行的工作(在这种情况下,只显示索引).

There are two divs, one displaying the indices of the ongoing eteration, the other appending the text The Interface is Still Responsive! on each Try Me button press. As you can see from the code, the eteration steps are scheduled by setTimeout some time interval apart, allowing for user interaction to take place and be processed as well. Thus, the eteration steps will continue to run as the user clicks on the button and triggers the update of the second div, maintaining the page's responsiveness while doing real progress with the work it has to perform (in this case, simply displaying indices).

这篇关于Eteration - 解释和示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆