I'm curious about the following two methods of declaring functions within a variable in Javascript. What's the difference between the two function declarations below? Both seem to work. Are there any drawbacks to using one over the other? They seem to be constructed slightly differently when looking at the debugger.
In addition, I'm fairly certain the first method is called 'object literal notation'. Is there a formal name for the second method?
var myVar = {
testProperty: 'testProperty',
// Object literal notation?
testFunc: function()
{
console.log('testFunc called');
},
// What's this called? 'Named function declaration'?
testFunc2()
{
console.log('testFunc2 called');
}
}
// Both work...
myVar.testFunc();
myVar.testFunc2();