What does 'this' refer to?


#1

I’m going through the ‘Intro to Node.js’ portion of the Website Starter Kit. I’m wondering what the keyword ‘this’ refers to in the file ‘app.js’.

Here’s my code: https://glitch.com/edit/#!/node-lemur


#2

You mean the this keyword in line 58?


#3

Yeah, line 58 in the file app.js


#4

In that context of the scope, this refers to resolutionsRequest, which calls on line 75 new XMLHttpRequest();. That’s why the script can access to responseText.

Check this example out (source):

var req = new XMLHttpRequest();
req.open('GET', 'http://www.mozilla.org/', false); 
req.send(null);
if (req.status == 200)
  dump(req.responseText);