Last active
September 24, 2018 13:18
-
-
Save SirSerje/6d1e6552a2262995a68733797bc67787 to your computer and use it in GitHub Desktop.
'barking dog'
This file contains 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
function Animal(name) { | |
this.name = name | |
} | |
Animal.prototype.getName = function() { | |
return this.name | |
} | |
function Dog(name) { | |
Animal.apply(this, arguments) | |
} | |
Dog.prototype = Object.create(Animal.prototype) | |
Dog.prototype.constructor = Dog | |
Dog.prototype.bark = function() { | |
return 'Dog ' + this.name + ' is barking' | |
} | |
const dog = new Dog('Aban') | |
console.log( dog.getName() === 'Aban' ) | |
console.log( dog.bark() === 'Dog Aban is barking' ); | |
This file contains 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
class Animal { | |
constructor(name) { | |
this.name = name | |
} | |
getName() { | |
return this.name | |
} | |
} | |
class Dog extends Animal { | |
bark() { | |
return `Dog ${this.name} is barking`; | |
} | |
} | |
const dog = new Dog('Aban') | |
console.log( dog.getName() === 'Aban' ) | |
console.log( dog.bark() === 'Dog Aban is barking' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
это желательно, но не обязательно, это не ошибка