user994165
user994165

Reputation: 9502

Using "this" in a function in Node.js

I'm trying to get access to this in a function, but it's undefined.

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

}

...

_.each(config, processEachPath);

Upvotes: 0

Views: 42

Answers (1)

Darkhogg
Darkhogg

Reputation: 14165

You need to explicitly bind it to the function:

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

// ...

(processEachPath.bind(this))();

Upvotes: 1

Related Questions