javascript - Node.js 如何将代码转换为事件?

标签 javascript node.js events

当你第一次运行你的 Node 程序时,第一个事件是如何/什么提供给事件循环的?你的程序是否像一个一直在执行的顶级回调? (我假设这个顶级回调通常是“server.listen()”?)

最佳答案

I'm confused about whether the event loop exists outside of the "main" script (or entry point) being ran, or if the event loop runs the "main" script itself

实际上,两者都是。事件循环是包装所有js代码执行的机制,只要有事件等待就不会停止。

what is the first event supplied to the event loop?

这是对主脚本的评价。 (或者更确切地说,最终将评估主脚本的 native Node.js 代码是首先放在 V8 事件循环中的代码)。

Is your program like a top-level callback that is being executed the entire time?

不,自始至终什么都不执行,每个回调都是单独执行的。

关于javascript - Node.js 如何将代码转换为事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44352385/

相关文章:

javascript - 无法在 GridView 内单击按钮时打开弹出式 div

javascript - 显示/隐藏层 onclick 不一致

javascript - http.get 问题 angular + nodejs

node.js - 如何在 Node.js (MEAN) 应用程序中的用户之间路由电子邮件?

javascript - NodeJs Testrunner 在设置 Express 服务器时卡住/停止

javascript - 每当调用其他类中的方法时调用该方法

对象中的对象中的 Javascript `this`?

javascript - 无论如何禁用 dojo 日期文本框的客户端验证?

javascript - Firebug : "event is not defined"

unit-testing - 如何在 angularjs 中使用自定义 dom 事件进行测试