Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonkorotkov/c2daf434c1d41fa0d9d5d61316c18e74 to your computer and use it in GitHub Desktop.
Save antonkorotkov/c2daf434c1d41fa0d9d5d61316c18e74 to your computer and use it in GitHub Desktop.
//https://jsfiddle.net/7Lucfkg5/6/
const Vehicle = function(name, sound) {
this.name = name
this.sound = sound
}
Vehicle.prototype.go = function() {
console.log(`${this.name} does the ${this.sound}`)
}
const Car = function(sound) {
Vehicle.call(this, 'car', sound)
}
Car.prototype = Object.create(Vehicle.prototype)
Car.prototype.stop = function() {
console.log(`${this.name} stops after ${this.sound}`)
}
const vehicle = new Vehicle('v', 'put put')
const car = new Car('wroom')
vehicle.go()
car.go()
car.stop()
console.log(car)
console.log(vehicle)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment