Last active
March 2, 2018 16:39
-
-
Save edtoken/887213efd713c9a298329db2369564d6 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 F(x){ | |
this.x = x; | |
this.getSumm = function(y){ | |
return x + y | |
} | |
} | |
var inst = new F(3); // вот тут мы получаем => {x: 3} | |
var result = inst.getSumm(2); // вот это сейчас не работает потому что нет getSumm, а должно вывести 5 | |
console.log(result) // вот тут должно вывести 5 | |
console.log(inst.x) // вот тут должно вывести undefined, задание со звездочкой | |
// А НИЖЕ ПОДСКАЗКА | |
// конструктор | |
function Animal(name) { | |
this.name = name; | |
this.speed = 0; | |
} | |
// методы в прототипе | |
Animal.prototype.run = function(speed) { | |
this.speed += speed; | |
alert( this.name + ' бежит, скорость ' + this.speed ); | |
}; | |
Animal.prototype.stop = function() { | |
this.speed = 0; | |
alert( this.name + ' стоит' ); | |
}; | |
var animal = new Animal('Зверь'); | |
alert( animal.speed ); // 0, свойство взято из прототипа | |
animal.run(5); // Зверь бежит, скорость 5 | |
animal.run(5); // Зверь бежит, скорость 10 | |
animal.stop(); // Зверь стоит |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment