Click here to Skip to main content
15,889,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
function Father(name,age) {
    this.name = name;
    this.age = age;
    if (typeof Father._initialized == "undefined") {
        Father.prototype.showname = function () { document.writeln("My name is " + this.name); };
        Father.prototype.sex="male";
        Father._initialized = true;
    }
}
function Son(name, age, girlfriend) {
    Father.apply(this, arguments);
    this.girlfriend = girlfriend;
    Son.prototype = new Father();
}
var son = new Son("shiy", 7, false);
son.showname();   //will make mistake
var x=new Son("shilf",23,false)
x.showname();      //it is right


why son.showname() will make mistake?
Posted
Updated 19-Dec-10 21:17pm
v3
Comments
Sandeep Mewara 20-Dec-10 3:25am    
What mistake?

Both looks same:
var son = new Son("shiy", 7, false);
son.showname(); //will make mistake
var x=new Son("shilf",23,false)
x.showname(); //it is right
AspDotNetDev 21-Dec-10 19:06pm    
Try reversing the order and see what happens. Also, try using a different variable name than "son".

1 solution

its strange both syntex are same... are you sured that you are not using any syntex error. but according to your code its look right.
C#
var son = new Son("shiy", 7, false);
son.showname();   //will make mistake
var x=new Son("shilf",23,false)
x.showname();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900