Possible Duplicate:
How do I make a callable JS object with an arbitrary prototype?
Let's say we have multiple individual functions that we can call individually in their own context; But they also inherit some other object's prototype. Like this:
//Here is the parent object:
var Human = function(){
this.isAlive = true;
};
Human.prototype.say = function(what){
alert(what + '!');
};
//These will inherit from it:
var ninja = function() {
alert("I'm a ninja!");
}
var samurai = function(){
alert("I'm a samurai!");
}
//Now, how can I make ninja and samurai behave like this:
ninja(); //I'm a ninja!
samurai(); //I'm a samurai!
ninja.say('Hello'); //Hello!
//And they should keep their inheritance. Like:
Human.prototype.die = function(){
this.isAlive = false;
}
ninja.die();
ninja.isAlive == false;
samurai.isAlive == true;
In other words, is there a way to have two objects that inherit another object's prototype, but are still callable as functions?
Note: I'm gonna use this in Adobe ExtendScript (aka Crippled Javascript), and it doesn't know much modern javascript. Like, Object.defineProperty doesn't work in it. So, is there a normal, standard way to do this?