Superclass and subclasses in JavaScript (ES5)

var Person = function(age){
  this.age = age;
};

Person.prototype.ageing = function() {
    this.age++;
};
var Hitman = function(age){
  Person.call(this, age);
};

Hitman.prototype = Object.create(Person.prototype);
Hitman.prototype.constructor = Hitman;
Hitman.prototype.kill = function(){};
var ben = new Hitman(26);
ben.ageing();
console.log(ben.age);//27

Add your comment