Much respect to you Chubbard. :)
Your example helped a lot.
My original 'example' was rather flippant. :P
I'm still running into a handful of problems though...
To elaborate on my 'cat' sample (keeping things as brief as possible):
function mammal(){
// 'mammals' constructor - My 'empirical' 'class'...
}
mammal.count = 0; // To keep track of the zoo I've created. No subclass can access this property. It's a 'static' property
// I could have declared this 'method' inside of my constructor
// with an anonymous function attached to (this.prototype.breathe).
mammal.track = function (){
this.count++;
}
mammal.prototype.breathe = function(){
alert("Inhale... Exhale...");
}
function cat(){
// 'cat' constructor
}
// All cats shall now become a type of mammal
cat.prototype = new mammal();
cat.prototype = function(){
// This anonymous function is the REAL constructor for my 'cat' 'superclass'
}
cat.prototype.meow = function(){
alert("Meow!");
}
function lion(){
// The king of jungle...
// I can keep track of the number of 'mammal' instances I create here
mammal.track();
}
// All lions are cats, afterall...
lion.prototype = new cat();
// Also note that I have no plans to extend the lion class.
// I have no need of a class below the 'idea' of a lion
lion.name = "Kitty"; // :}
// Here's where I get confused...
// I can set (lion.name) via instances, can't call (lion.pounce), but (lion.prototype.roar) works all day long! o_0
lion.pounce = function(){
alert(this.name+" pounces...")
}
lion.prototype.roar = function(){
alert(this.name+" doesn't meow, he ROOOAAARS!");
}
// With these constructs in place, I can now script...
$(document).ready(function(){
var rory = new lion();
var napoleon = new lion();
alert("We have "+mammal.count+" mammals running about");
// This is 'Rory'...
rory.name = 'Rory'; // Respect the pun...
rory.roar();
// This is 'Napoleon'...
napoleon.name = 'Napoleon';
napoleon.breathe(); // Napoleon can't breathe... he didn't inherit mammal.prototype.breathe(), for some reason
napoleon.roar(); // How am I able to set (lion.name), but not call lion.pounce()?
napoleon.pounce();
});
You were right of course, every class in my chain right up to the creation of the final instance(s), is a prototype function. But why does (lion.name) work but not (lion.prototype.name). Conversely, why might lion.prototype.pounce() work, when lion.pounce() borks?
Napoleon and Rory are both Lions afterall...
I have loads more Javascript questions... It's a very strange language... ;)