# Function fName() vs. fName = function() \[FMX\]

**URL:** https://forum.kirupa.com/t/function-fname-vs-fname-function-fmx/64981
**Category:** Uncategorized
**Created:** [September 22, 2004, 12:26am UTC](https://forum.kirupa.com/t/function-fname-vs-fname-function-fmx/64981 "2004-09-22T00:26:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![kill\_robot\_kill](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kill_robot_kill/32/359_2.png) [@kill\_robot\_kill](https://forum.kirupa.com/u/kill_robot_kill)
#### Post date: [September 22, 2004, 12:26am UTC](https://forum.kirupa.com/t/function-fname-vs-fname-function-fmx/64981/1 "2004-09-22T00:26:31Z")

</div>

Ok, so I am messing around with some code and noticed that there is a difference between these two function declerations.

```auto
function fName(){//}
fName = function(){//}

```

I’ve always used **function fName()** before, but I am starting to learn some OOP, and figured I could change to **fName = function()** to indicate that it is a constructor. I thought it was a pretty good idea, until my code started behaving off.

An example of this is:

```auto

function Animal() { // Animal Constructor
}
Cat.prototype = new Animal(); 
function Cat() { // Cat Constructor
} 

```

If I type the “cat constructor” as **Cat = function()** it doesn’t work unless its before “cat.prototype”, now if I leave it as is, it will work if its called before or after the cat.prototype.

Why is that, should I NEVER use\*\* fName = function()\*\* to declare a function, or is my example just off? I guess I’m just looking for an explanation of this.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 22, 2004, 12:40am UTC](https://forum.kirupa.com/t/function-fname-vs-fname-function-fmx/64981/2 "2004-09-22T00:40:42Z")

</div>

nothing is accessible before its defined _except_ function Name() declared functions. Its not a problem with Name = function definitions, its just a feature of function Name definitions.

There are a few differences and each have their place. One difference you just pointed out. Another is that you can’t define functions through targets or object methods using the function Name style. Prototype methods, for example, have to use Class.prototype.name = function(){ … } Contrary to that, AS 2 methods have to use function name(){ … }

Their just different. Niether is necessarily right or wrong.
