// inheritance using
// constructor functions

// constructor function
function Person(name, age) {
  this.name = name
  this.age = age
}

// add greet() method to Person prototype 
// never add it inside Person function 
// to prevent it from being copied to every object created
Person.prototype.greet = function () {
    console.log(this.name, this.age)
}

// another constructor function 
// that extends Person via .call() method 
function Developer(name, age, proglang) {
  Person.call(this, name, age)
  this.proglang = proglang
  this.code = function () {
    console.log(this.proglang)
  }
}

// set Developer.prototype to an object
// that inherits from Person.prototype
// to inherit the greet() method
Developer.prototype = Object.create(Person.prototype)

let d1 = new Developer("devon", 23, "java")
console.log(d1.name, d1.age, d1.proglang)
d1.greet()
d1.code()

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: