Created
September 27, 2015 22:12
-
-
Save qetr1ck-op/fde34608e4532f82d166 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
// 1. constructor | |
function Animal(name) { | |
this.name = name; | |
this.speed = 0; | |
} | |
// 2. methods in prototype | |
Animal.prototype.run = function(speed) { | |
this.speed += speed; | |
console.log(`${this.name} runnig, speed is ${this.speed}`); | |
}; | |
Animal.prototype.stop = function() { | |
this.speed = 0; | |
console.log(`${this.name} стоит`); | |
}; | |
var animal = new Animal('Banny'); | |
console.log( animal.speed ); // 0, from __proto__ | |
animal.run(5); // Banny runnig, speed is 5 | |
animal.run(5); // Banny runnig, speed is 10 | |
animal.stop(); // Banny runnig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment