-3

I've seen the following code in Alexa:

var Response = function (context, session) { this._context = context; this._session = session; };

I'm unsure what it is trying to so, specifically this part:

_context.

Thanks

  • it's a class constructor that initialized the object properties. – Barmar Dec 30 '17 at 00:57
  • You should read a tutorial on object-oriented programming in Javascript. – Barmar Dec 30 '17 at 00:58
  • Looks just like an ordinary constructor to me, what;s the problem? Also, worst ever question title- how is that going to help others in the future with the same problem. Please update it – Alicia Sykes Dec 30 '17 at 01:50

1 Answers1

2

It's a class constructor that initializes the properties of the new object from its parameters.

var Response = function(context, session) {
  this._context = context;
  this._session = session;
};

var r = new Response("a context", "session 1");
console.log(r);
Barmar
  • 741,623
  • 53
  • 500
  • 612