prototypal inheritance - Javascript call the base class constructor -
person
base class , emp
inherits person
. trying use name
, location
properties of person
in emp
.
function person(name, location){ this.name = name; this.location = location; } person.prototype.getname = function(){ return 'name: ' + this.name; } function emp(id, name, location){ this.id = id; person.call(this, name); person.call(this, location); } emp.prototype = object.create(person.prototype); var e1 = new emp(1, 'john', 'london'); e1.id // 1 e1.name // 'london' e1.location //undefined
what causing error , why name taking value of london?
why calling constructor twice single argument?
function emp(id, name, location){ this.id = id; person.call(this, name, location); }
Comments
Post a Comment