Answer the question
In order to leave comments, you need to log in
Why doesn't this refer to the global object when running the script via node?
If you create app.js, add the following:
'use strict';
console.log(this)
{}
<ref *1> Object [global] {
...
}
Answer the question
In order to leave comments, you need to log in
Because they did it a long time ago and there is no way to fix it.
Inside the module this === module.exports .
DEP0092: Top-level this bound to module.exports
To get global, you need to explicitly refer to it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question