I am trying to run a function of an object created using a constructor function. However, I am unable to do so as I keep getting and error saying “TypeError: mutant_cat.meow is not a function. (In 'mutant_cat.meow()', 'mutant_cat.meow' is undefined)”. This is my constructor function:
function Cat(legs, sound) {
this.legs = legs;
this.sound = sound;
var meow = function() {
document.write(sound);
}
}
And this is where I create the object and attempt to run its function:
var mutant_cat = new Cat(5, "eeeeeee");
mutant_cat.meow();
Any help is greatly appreciated.
meowto be onthis:this.meow =Better yet, put it on the prototype:Cat.prototype.meow =