Here I am trying to understand few concepts of inheritance in javascript.I have created person class and trying to inherit it in Customer class.
var Person = function(name) {
this.name = name;
};
Person.prototype.getName = function() {
return this.name;
};
Person.prototype.sayMyName = function() {
alert('Hello, my name is ' + this.getName());
};
var Customer = function(name) {
this.name = name;
};
Customer.prototype = new Person();
var myCustomer = new Customer('Dream Inc.');
myCustomer.sayMyName();
Every time a new object gets created ,javascript engine basically calls prototype's constructor. here I am trying to understand few things:
if Customer prototype is referring to Person object.So creation of new Customer object should contain only Person property/Method not the Customer property/Method.How Customer property get attached to the new Customer object (myCustomer)?
Am I missing some javascript concept here?