簡體   English   中英

在Node.js中的函數中使用“ this”

[英]Using “this” in a function in Node.js

我正在嘗試通過函數訪問this函數,但是它是未定義的。

function processEachPath(element, index, list) {
    logger.debug(this);

}

...

_.each(config, processEachPath);

您需要將其顯式綁定到該函數:

function processEachPath(element, index, list) {
    logger.debug(_this);
}

// ...

(processEachPath.bind(this))();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM