Skip to content

Instantly share code, notes, and snippets.

@prashantsani
Created February 17, 2023 10:41
Show Gist options
  • Select an option

  • Save prashantsani/1757a36190c968216faa37feffc28db5 to your computer and use it in GitHub Desktop.

Select an option

Save prashantsani/1757a36190c968216faa37feffc28db5 to your computer and use it in GitHub Desktop.
Classical Inheritance
function Car(options) {
this.title = options.title;
}
Car.prototype.drive = function () {
return 'drive'
}
function Toyota(options) {
Car.call(this, options);
this.color = options.color;
}
Toyota.prototype = Object.create(Car.prototype);
Toyota.constructor = Toyota;
Toyota.prototype.honk = function () {
return 'honk'
}
const toyota = new Toyota( { color: 'red', title: 'new toyota' });
console.log(toyota)
console.log(toyota.drive())
console.log(toyota.honk())
// results:-
// {"title":"new toyota","color":"red"}
// drive
// honk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment