This is the JavaScript code I am working with: (Check it here)
$(function () {
function Cat()
{
this.Meow = function (sound) {
alert("Meow: " + sound);
}
this.Kick = function () {
MakeNoise();
}
var MakeNoise = function () {
Meow("noise");
//Cat.Meow("noise");
//self.Meow("noise");
//this.Meow("noise");
}
}
var c = new Cat();
c.Kick();
});
When trying to call the Kick
function, an error "Meow is not defined" keeps popping up. This occurs no matter which method I use in the MakeNoise
function.
I've also attempted to use prototyping but faced the same error:
Cat.prototype.Meow = function (sound) {
return this.Meow(sound);
}
I believe there must be a simple solution to this problem, but I'm struggling to successfully invoke the Meow
function of the "Cat" class. Any suggestions on how to accomplish this?
Additionally, does this design structure even make sense? My goal was to have Kick
and Meow
as public functions, and MakeNoise
as private.