Last active
August 29, 2015 14:27
-
-
Save kulakowka/8495ecd2203e3a1434c7 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
function Animal(name) { | |
this.name = name; | |
this.speed = 0; | |
} | |
Animal.prototype.run = function(speed) { | |
this.speed += speed; | |
console.log(this.name + ' бежит, скорость ' + this.speed); | |
}; | |
Animal.prototype.stop = function() { | |
this.speed = 0; | |
console.log(this.name + ' стоит'); | |
}; | |
function Rabbit(name) { | |
Animal.apply(this, arguments); | |
this.size = 100; | |
} | |
Rabbit.prototype = Object.create(Animal.prototype); | |
Rabbit.prototype.constructor = Rabbit; | |
Rabbit.prototype.jump = function() { | |
this.speed++; | |
console.log(this.name + ' прыгает'); | |
}; | |
// переопределим метод run() | |
Rabbit.prototype.run = function(speed) { | |
Animal.prototype.run.apply(this, arguments); | |
this.jump(); | |
}; | |
var rabbit = new Rabbit('Кроль'); | |
console.log(rabbit); | |
rabbit.run(500); | |
rabbit.stop(); | |
rabbit.jump(); | |
console.log(rabbit.speed); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment