2
var Result = Result || {};

Result.Controller = function (){
var _self = this;
 _self.router = new v2.Router(_self);
};

I have above code of javascript, here I want to know where will "this" points to? Is it Controller or Result? and why?

JLRishe
  • 90,548
  • 14
  • 117
  • 150
Pritam
  • 939
  • 2
  • 12
  • 36
  • 3
    `this` is set in Javascript according to how a function is called. You can read about the different ways it is set here: http://stackoverflow.com/questions/25374991/why-this-in-object-function-is-different-when-called-directly-from-addeventlis/25375081#25375081 and here http://stackoverflow.com/questions/19623738/how-to-avoid-this-refering-to-the-dom-element-and-refer-to-the-object/19623763#19623763 – jfriend00 Feb 19 '15 at 04:33
  • 2
    There's absolutely no way to tell for sure just by looking at the code you posted what the value of `this` will be when the function is called. It could literally be anything. It is necessary to examine the ways the function is called in order to know. – Pointy Feb 19 '15 at 04:40
  • possible duplicate of [How does the "this" keyword work?](http://stackoverflow.com/questions/3127429/how-does-the-this-keyword-work) – Qantas 94 Heavy Feb 19 '15 at 04:40

0 Answers0