javascript prototype throw the error as "Object [object Object] has no method" -


i doing prototype inheritance method test.. getting error, after copied instance existing object...

what wrong here..

my test :

var human = function(name){     this.name = name; }  human.prototype.say = function(){     alert(this.name); }  var male = function(gender){     this.gender = gender; }  male.prototype.gender = function(){     alert(this.gender); }  var inst1 = new human('nw louies'); inst1.say();  var inst2 = new male("male"); inst2.prototype = new human("sa loues philippe"); //i copying instance of human inst2.gender(); inst2.say(); // throw error "undefined" 

what wrong here.. 1 me understand mistake?

live demo here

you need say

var male = function(gender){     this.gender = gender; }  male.prototype = new human(); 

don't forget need set name property of male objects. expose setname method on human , call in male constructor function, example.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -