@Quintis

Кто может объяснить все что есть в функции и как она работает простым языком?

Здравствуйте друзья, прохожу тему ООП на free code camp но не до конца понимаю как что работает в функции, может кто-то объяснить все на простом языке)?
function Animal() { }

Animal.prototype = {
  constructor: Animal,
  eat: function() {
    console.log("nom nom nom");
  }
};

function Dog() { }

// Add your code below this line
Dog.prototype = Object.create(Animal.prototype);

let beagle = new Dog();
beagle.eat();  // Should print "nom nom nom"
  • Вопрос задан
  • 159 просмотров
Пригласить эксперта
Ответы на вопрос 1
https://developer.mozilla.org/en-US/docs/Learn/Jav...
https://github.com/getify/You-Dont-Know-JS/blob/ma...

Можно еще погуглить Прототипное наследование
Кстати приведенный пример достаточно странный, в идеале конструктор пишется как то так
function Person(first, last, age, gender, interests) {
  this.name = {
    first,
    last
  };
  this.age = age;
  this.gender = gender;
  this.interests = interests;
};
//The methods are all defined on the constructor's prototype. For example:
Person.prototype.greeting = function() {
  alert('Hi! I\'m ' + this.name.first + '.');
};
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы