1

I'm a beginner in javascript programming and I notice that there are some cases where a function is defined as

myfunc : function() {...},

and other cases where it is defined as:

function myfunc(){...}

Can someone explain what the difference is, and when should one be used over the other.

tckmn
  • 52,184
  • 22
  • 101
  • 145
  • Note that this isn't a duplicate of the question that was linked. The first case that you have defined can only be used within object literals, and the second case that you have defined cannot be used inside object literals. – influxd Nov 15 '15 at 16:49
  • 2
    @influxd: In that case the difference would be even more obvious, as the result is not the "same" any more. So yes, the OP should have posted the whole literal, but I think it would have been closed anyway so I'm not going to reopen it. Still, the linked dupe does explain the difference between delcarations and expressions which applies here as well. – Bergi Nov 15 '15 at 16:54
  • @influxd, Thanks, that helped! – Dimitar Stratiev Nov 15 '15 at 17:32

0 Answers0