I am trying to solve a problem where I have the following piece of code:
var piggie = new Animal(Animal.PIG);
How can a Constructor function (new Animal) also be an Object with properties (Animal.PIG)?
I have tried this solution:
function Animal(type) {
this.typeOf = type;
return {
PIG: 'Pig'
};
}
But Animal.PIG is undefined? JS Fiddle is here: http://jsfiddle.net/bufr2b4c/
thisthiswhich makes using a constructor function pointless.