1

Is there a different outcome (scope etc...) between the following two function declarations?

var myObj = {
    foo: function myName() {}
}

var myObj = {
    foo: function() {}
} 
Andrew
  • 946
  • 9
  • 19

2 Answers2

2

No, the scope is the same. In javascript anonymous functions can be named and its good practice to do so because when debugging they are named in stack traces. Also you can refer to the function inside itself. More details here.

Donatas Bacius
  • 646
  • 6
  • 16
1

when you give a name to the function, it's only available from inside that function

var myObj = {
   foo: function myName() {
        myName()
   }
}
Edgar Zakaryan
  • 576
  • 5
  • 11