Search code examples
actionscript-3functionfunction-literal

Difference between functions and function literals in ActionScript 3?


What is the difference between the following two function definitions in ActionScript 3?

f = function(arg) {
  // body
}

and

function f(arg) {
  // body
}

Solution

  • There is very little practical difference in the example you have provided. The difference is really at compile time. The one worth noting is that that in first case, f = function, you can redefine the value of f at anytime, while in the second case, redefining f would cause a compiler error.

    General best practices is to use the second.

    Hope that helps.