Created
June 28, 2019 12:19
-
-
Save antonkorotkov/c2daf434c1d41fa0d9d5d61316c18e74 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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