I'm trying to create 2 objects that share the same way of implementing:
function Human(hand,leg,head,body,foot1,foot2){
this.hand = hand;
this.leg = leg;
this.head = head;
this.body = body;
this.feet = [foot1,foot2];
}
function Robot(hand,leg,head,body,foot1,foot2){
this.hand = hand;
this.leg = leg;
this.head = head;
this.body = body;
this.feet = [foot1,foot2];
}
And I want them to have different prototypes:
Human.prototype.scream = function(){
alert("HUMANNN");
//some other functions
};
Robot.prototype.scream = function(){
console.log("ROBOOBOT");
//some other functions
};
var Tom = new Robot(1,2,3,4,5,6);
Tom.scream();
var I = new Human(312314123,2141123,213131412,4121312,132124,12313);
I.scream();
Is there a better way to create the functions Human
and Robot
so that I don't have to write it twice?
I tried
function Robot(hand,leg,head,body,foot1,foot2){
Human(hand,leg,head,body,foot1,foot2);
}
var Micky = new Robot(1,2,3,4,5,6);
Micky.scream();
But it didn't work.