[英]Using “this” in a function in Node.js
I'm trying to get access to this
in a function, but it's undefined. 我正在尝试通过函数访问
this
函数,但是它是未定义的。
function processEachPath(element, index, list) {
logger.debug(this);
}
... ...
_.each(config, processEachPath);
You need to explicitly bind it to the function: 您需要将其显式绑定到该函数:
function processEachPath(element, index, list) {
logger.debug(_this);
}
// ...
(processEachPath.bind(this))();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.