Declare a class using prototype?


Let's say you want to make a new class, let's call it Fox, that inherits all the properties from an class, Animal. I would figure you could just do something like:

Fox.prototype = new Animal();

but it seems like you have to do this annoying step of just declaring an empty constructor function for the class first:

var Fox = function() {};

is there any way to do it without creating that empty class first? something more efficient?


I am not sure, I am new to this, some expert should comment on this as even I am not clear:

You could do:

var Fox = new Animal("specify name",number);


var Fox;
Fox.prototype = new Animal("specify name, number);

The reason being,
1st : you have to declare a variable "Fox" else it throws an exception as it doesnt understand what "Fox" is. You can leave it as an empty variable.
2nd : If you specify :

Fox.prototype = new Animal();

this will not work as Animal takes two parameters, so you will have to define parameters for this code to work.

If you 1st define the "Fox" parameters via constructor, and define same properties of Animal inside Fox as well,
then it can relate those two.

var Fox = Animal.constructor();

You can try this, it will clone the Animal function to Fox.