Javascript-форум (https://javascript.ru/forum/)
-   Events/DOM/Window (https://javascript.ru/forum/events/)
-   -   Проблема с пониманием this (https://javascript.ru/forum/events/80874-problema-s-ponimaniem.html)

Coreman 19.08.2020 14:17

Проблема с пониманием this
 
Доброго времени суток,
не могу понять,почему при вызове update.call()
в консоль приходит undefined .
const bruce = {name: 'Bruce'};
const madeline = {name: 'Madeline'};


function greet() {
    return `Привет ! Меня зовут ${this.name}`; 
}


greet.call(bruce); 
greet.call(madeline);

function update(birthYear,occupation){
    this.birthYear = birthYear;
    this.occupation = occupation;
}

console.log(update.call(bruce,1991,'singer'));
console.log(update.call(madeline,1988,'actress'));

:help:

Nexus 19.08.2020 14:18

Потому что ваш метод update ничего не возвращает.

Coreman 19.08.2020 14:23

Nexus,
а понял, спасибо!


Часовой пояс GMT +3, время: 15:01.