0

in short, what's the difference between

var MyModule = {
   func: function() {}
};

and

var MyModule = {
   func: function f() {}
};

I used to use the first way. But when I see angular docs it's is usually the second way. why, and what's the difference?

2 Answers 2

1

There is no difference in how this code is executed, but the second version can help you with debugging. If you see a stacktrace for some error with first version you will see info about some anonymous function and in second version you will see function name.

ESLint has a rule for this convention. You can read about it here

Sign up to request clarification or add additional context in comments.

Comments

1

The first on has an anonymous function and the second has a named function.

Both will work the same. It's just to ensure readability. Adding a sample code to demonstrate both.

var MyModule = {
   func: function() { return 10}
};

var MyModuleTwo = {
   func: function f() { return 10}
};

//both will return 10
console.log(MyModule.func())
console.log(MyModuleTwo.func())

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.