I want to resolve this confusion in my mind once and for all! I am struggling to access some of my class properties and methods. While I understand that I could use an object literal and append all references with the object's name, such as animal., I'm curious to learn how to handle this when dealing with an instantiated class.
Let me provide a quick example from my code:
function animal(){
this.type = "Reptile";
this.sayType = function(){
// Based on my past experiences, "this" here still refers to "animal"
alert(this.type);
};
this.names = {
name : "Lizard",
sayTypeAndName : function(){
//Now, "this" points to "names" rather than the "sayTypeAndName" method or the parent
//class: animal. When I attempt to reference "animal" like I would in an object literal
//or construct the class, I encounter an error stating that the method below
//does not exist. HOW CAN I PROPERLY REFER TO THE PARENT CLASS PROPERTIES?
//SHOULD I INCLUDE THE PARENT CLASS PROPERTIES AND METHODS INTO MY "names" OBJECT?
animal.sayType(animal.type+" "+this.name);
}
};// End of names object
}// End of class
Thank you all for any assistance you can provide on this matter.