搜尋

首頁  >  問答  >  主體

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

PHPzPHPz2865 天前577

全部回覆(2)我來回復

  • 天蓬老师

    天蓬老师2017-04-17 16:04:27

    看註解:

    this is req, which is a streamthis is req, which is a stream

    此时this指向req,而req对外可以当做是stream

    此時this指向req,而req對外可以當做是stream來用,就只是變個名字,看起來更清楚吧,沒啥特殊意義。 🎜

    回覆
    0
  • 迷茫

    迷茫2017-04-17 16:04:27

    我只能說這個demo寫得爛,不必迷信&過度揣測其用意。


    正常的類似的寫法是這樣的

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

    可以在閉包裡引用上層作用域的this

    回覆
    0
  • 取消回覆