I am kind of back engineering a javascript project and need to inject a function into some already writeen code.
I want to be able to call something like the following function in javascript:
human.mouth.shout(word);
So this would call the function that makes the object 'shout'.
My question is, how I create child attributes of the human object. As far as I know, I can only have one nested function in javascript, so at the most basic I have something like this:
function HumanObj(){
this.shout = function(word){
alert(word);
}
}
Then to call this, I would use:
var human = new HumanObj;
human.shout("HELLO WORLD");
So this would give us our alert: "HELLO WORLD".
So how would I break this up so I could call it using the following?
var human = new HumanObj;
human.mouth.shout("HELLO WORLD");
Have tried this, but didn't work - assume you can't have too many levels of nested functions...
function HumanObj(){
this.mouth = function(){
this.shout = function(word){
alert(word);
}
}
}
Thanks!