Subclasses instantiating superclass of class Human I have a test which looks like this:


Create a base class Human 
Human class needs to have a method Talk
The Human class needs to have to descendant class Man and Woman
Both Man and Woman should have their own Talk method (basically rewrite the method)
The Man class should have a private property _foo
It should have a method getInfo (which needs to be an Ajax call and log the response)
I need to make 1000 instances of the Women class in the window namespace (I mean global)
On document.body single click, a random Woman should call the Talk method
On document.body double click, the Man's getInfo method should be called




function Human(){};

Human.prototype.talk = function(){
    console.log('Make an Human sound');
}

function Woman(){
    Human.call(this);
}


Woman.prototype = Object.create(Human.prototype);
Woman.prototype.constructor = Woman;

Woman.prototype.talk = function(){
    console.log('Miau');
}

function Man(){
    var foo = 10;
    Human.call(this);
}


Man.prototype = Object.create(Human.prototype);
Man.prototype.constructor = Man;

Man.prototype.talk = function(){
    console.log('Wuff');
}

Man.prototype.getInfo = function(method, url){
    var xhr = new XMLHttpRequest();

    xhr.open(method, url);
    xhr.send(null);

    xhr.onreadystatechange = function() {           
        console.log('Ajax response: ' + xhr.readyState);            
    };
}

var woman = new Woman();

console.log('woman instance of Woman ' + (woman instanceof Woman));
console.log('woman instance of Human ' + (woman instanceof Human));

woman.talk();

var man = new Man();

console.log('man instance of Man ' + (man instanceof Man));
console.log('man instance of Human ' + (man instanceof Human));

man.talk();

womans = [];
for(var i = 0; i &lt; 1000; i++) {

    womans[i] = new Woman();        
}

document.body.onclick = function(){     
    var randNr = Math.floor((Math.random()*1000)+1);
    womans[randNr].talk();
    console.log('Random Woman: ' + randNr);
 }
 document.body.ondblclick = function(){
          Man.prototype.getInfo();
    }
Some opinions:


function Woman(){
    Human.call(this);
}
Woman.prototype = new Human();



Don't use new for prototype (even when it doesn't matter here as long as Human is empty, but the Huma.call(this) suggests otherwise). Check https://stackoverflow.com/q/10898786/1048572


// Woman subClass
function Man(){



Apparently not.


    var _foo = 10;



It's a local-scoped ("private") variable anyway, you don't need to prefix it with an underscore. Notice that it is only accessible from functions declared within the constructor, of which you don't have any.


    return Human.call(this);



No reason to return anything here. It might even be wrong it Human did return an object.


Man.prototype.getInfo = function(method, url){
    […]
}



This doesn't seem to have anything to do with instances of Man, so I wonder why it is a method? But that's probably just the design of your test case.


console.log('man private variable _foo: ' + (man._foo));



Not sure what you did expect, but yes, since _foo has been a variable and not a property of the object so this is undefined.


document.body.onclick = function(){     
    […]



…is missing a closing brace.


var randNr = Math.floor((Math.random()*1000)+1);
womans[randNr].talk();



No. That randNr will be in the range 1-1000 (both inclusive), while your array indices are 0-999. With a small chance, this will throw an exception. Remove the +1.


console.log('Random Woman: ' + randNr);



…and add it here if you want that output one-based.


Man.prototype.getInfo();



That confirms what I said above - you don't use an instance for that method. You should hardly ever call methods on the prototype object - man.getInfo() would be better. But if you really intended this to be a static function, you might write Man.getInfo = function() {…}; and then call Man.getInfo();.