9

I have a script like this:

var test = function(){
    console.log('From test: '  + this);
};
console.log(this);
test();

Which I run using node test.js. And what I would expect from the script is for both this to point to global object, however only this within the test function points to global object. console.log(this); actually points to an empty object.

I am trying to understand why node.js has this behaviour and am I misunderstanding something about how this keyword works in node.js.

thefourtheye
  • 206,604
  • 43
  • 412
  • 459
Vitalij
  • 4,437
  • 9
  • 39
  • 65

0 Answers0