As the other answers mentioned, you have a significant issue with the inheritance model.
At this line:
ChildClass.prototype = new BaseClass(name,LastName);
The name and LastName are probably undefined, since you are looking for them in the global scope (or the scope you defined your classes in). They have absolutely no connection with what is passed as argument to the constructor of ChildClass.
Instead, you want to call the base class constructor from the child constructor, like this:
function ChildClass(name, lastName){ // parameters should be declared
BaseClass.call(this, name, lastName); // call the base class
}
By calling BaseClass with the first argument this, you have essentially run the code of the BaseClass function with this being your new instance of ChildClass. The code in BaseClass has set childClass.name and childClass.lastName properties, so you don't need to do that in ChildClass.
To finish the inheritance model, you also need to inherit methods from the prototype of the base class:
ChildClass.prototype = Object.create(BaseClass.prototype);
Notice that you don't inherit them from an instance of BaseClass, because you don't know with what parameters you should call the constructor and it's not always correct to call it with no parameters.
One final thing, make sure that the line setting ChildClass.prototype is before any method/property defined on ChildClass.prototype, otherwise you simply overwrite it.
Full code:
//===== BaseClass
function BaseClass(name,lastName){
this.name = name;
this.lastName = lastName;
}
BaseClass.prototype.getName = function() {
return this.name;
}
BaseClass.prototype.getLastName = function() {
return this.lastName;
}
BaseClass.prototype.saveName = function() {
console.log("In base class function.");
}
//======= ChildClass
function ChildClass(name, lastName, age){
BaseClass.call(this, name, lastName);
this.age = age;
}
ChildClass.prototype = Object.create(BaseClass.prototype);
ChildClass.prototype.saveName = function() {
console.log("In child class function.", this.name, this.lastName, this.age);
}
//=========== usage
var childClass = new ChildClass('john', 'doe');
childClass.saveName();