理解和编写 JS 中的回调
Understanding and writing callback in JS
app.get('/', function (req, res) {
res.send('Hello World!');
});
我知道如何处理上面的代码,但我想提高我的水平,这样我就可以知道它在后面是什么样子的。
我的猜测如下
var app = {
get:function(first, second){
first= function(){
//do something
},
second = return second(){
}();
}
}
顺便说一句,我确定我的猜测是错误的。
回调用于处理异步问题,一个例子是:
var first = function (callback) {
var hi = reallyLongFunction();
return callback(hi);
};
var second = function () {
first(function(hiFromFirstFunction) {
//scope of this function has hiFromFirstFunction and anything within the second function
});
};
相关文章:
- 要求未定义JS回调参数
- 从新的WordPress媒体上传程序获取JS回调
- 重构DRY代码的Node.JS回调
- Material Design Lite所有元素加载JS回调
- 未为路由器应用程序调用Node.Js的回调
- Node.js exec调用从不调用回调
- 在Backbone.js中将回调绑定到此
- YepNopeJS:在小JS文件完全加载之前触发回调
- Node.js使变量等待分配,直到回调函数完成
- js回调到基于生成器的代码
- Node.js,为事件分配回调函数'数据'
- 请求js中的回调问题
- Node.js正确的回调错误句柄
- Flux+React.js-回调操作是好是坏
- 将匿名JS函数作为回调传递
- node.js mongojs findOne回调返回错误为null
- 在 Node.js 中脱离回调函数中的“for”循环
- 在其他回调js中调用回调
- Ember 是否有总是回调.js .then 函数
- 回调JS代码