Ok, so I am messing around with some code and noticed that there is a difference between these two function declerations.
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:
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.