When angular creates your controller, it will use the new keyword for the function you passed. Thus, it will build a new object using the constructor you submitted. Building objects using the constructor function will always return an instance of the newly created object.
There are some details about the build process (see this SO answer)
- When the returned object matches
this , it can be omitted since it will be returned by default. - If you return some primitive type, zero, or something else (described in another SO answer), this is also returned.
- When an instance is returned, a link to that instance will be returned.
source share