node.js - node 回调函数中 var temp = this 的意义

【字号: 日期:2022-09-21浏览:26作者:雯心

问题描述

问题解答

回答1:

看注释:

this is req, which is a stream

此时this指向req,而req对外可以当做是stream来用,就只是变个名字,看起来更清楚点吧,没啥特殊意义。

回答2:

我只能说这个demo写得烂,不必迷信&过度揣测其用意。

正常的类似的写法是这样的

var xx = function() { var that = this;return funtion() {that.xxx }}

可以在闭包里引用上层作用域的this

相关文章: