0

What means that code?

function myConnectController($state, $my, myService, apiJobs, apiMy) {
  var ctrl = this, mySequenceDataService; // this statement
  ...
  function init() {
    mySequenceDataService = $my.mySequenceDataServiceFactory.createInstance({
  ...
  });}
  ...
}

Is that some kind of inheritance?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Qback
  • 4,310
  • 3
  • 25
  • 38
  • 5
    That `var` declaration declares two variables: one called "ctrl" and one called "mySequenceDataService". – Pointy Jul 04 '18 at 14:19
  • @Pointy then what's value of `mySequenceDataService` variable? – Qback Jul 04 '18 at 14:20
  • 1
    at that point is has no value. the value is set on this line mySequenceDataService = $my.mySequenceDataServiceFactory.createInstance({ ... });} – locomain Jul 04 '18 at 14:22
  • It's `undefined` because it is not initialized (at least not in the code you posted). – Pointy Jul 04 '18 at 14:24

1 Answers1

2

var within a function declares a (local) variable.

You can "chain" assignments after one var keyword by comma seperating them.

var ctrl = this, mySequenceDataService;
               ^// comma seperating variables

In this example mySequenceDataService is assigned undefined, but is local and will not try to look in other scopes or the global scope for a variable named like that, nor assign the value(which happens in your init method) to a global scope variable.

you can also do this:

 var foo = 'hello', baz = 'world', bal = 'universe';
Tschallacka
  • 27,901
  • 14
  • 88
  • 133