简体   繁体   English

JavaScript异步编程

[英]JavaScript asynchronous programming

Recently, I began studying JavaScript, and I reached a topic about asynchronous coding, or some refer to it as function parameter or callback (node.js to be more specific). 最近,我开始学习JavaScript,并且达到了有关异步编码的主题,或者有人将其称为函数参数回调 (更具体地讲是node.js)。

I tested some stuff with it, but can`t get the idea of it. 我用它测试了一些东西,但是无法理解。 For example 例如

window.addEventListener("click", function(){ alert("HELO"); }, true);

will do nothing. 什么也不会做。 Can somebody explain in short what exactly is the idea behind asynchronous coding and what are these callbacks, also a 3-4 line example will be appreciated. 有人可以简短地解释一下异步编码背后的确切含义是什么,这些回调是什么,还有3-4行示例。

The code you have written requires the window object which is not a part of the node.js environment. 您编写的代码需要window对象,该对象不是node.js环境的一部分。

I recommend watching ryan dahl's introduction to node.js 我建议观看ryan dahl对node.js的介绍

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM