# When to used named vs. anonymous functions

**URL:** <https://forum.kirupa.com/t/when-to-used-named-vs-anonymous-functions/232928>\
**Category:** flash\
**Created:** [July 18, 2007, 8:07pm UTC](https://forum.kirupa.com/t/when-to-used-named-vs-anonymous-functions/232928 "2007-07-18T20:07:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ironchefmoto](https://avatars.discourse-cdn.com/v4/letter/i/91b2a8/32.png) [@ironchefmoto](https://forum.kirupa.com/u/ironchefmoto)\
**Post date:** [July 18, 2007, 8:07pm UTC](https://forum.kirupa.com/t/when-to-used-named-vs-anonymous-functions/232928/1 "2007-07-18T20:07:20Z")

</div>

Long ago, when I started writing Actionscript, I wrote functions in the “named” variety:

```auto
function doSomething(parameter:String):Void
{
trace("MONKEYS are attacking " + parameter);
}

```

Then, I started writing them as named functions:

```auto
var doSomething:Function = function(parameter:String):Void
{
trace("MONKEYS are attacking " + parameter);
}

```

Then, I took a few Adobe training classes, and I ended up getting into the habit of writing functions like this:

```auto
this.doSomething = function(parameter:String):Void
{
trace("MONKEYS are attacking " + parameter);
}

```

I think the 2nd variant is just a slack-\*\*\* way of doing an anonymous function.

\*\*What is the “best practice” for writing functions? When do I use one or the other? I know the named function syntax is important for classes (starting to write more of those now). I also know that, in AS 3.0, there were some changes to function declarations, but I want to focus on AS 2.0 here.

Any suggestions? Guidance?\*\*

Thanks,  
IronChefMorimoto
