JavaScript object method's this context |

Опубликовано: 16 Апрель 2024
на канале: Mayank Srivastava
241
10

Here we a person object having a name property with string value and a method getName which returns the name property present in the current context.
So if we execute the getName object method directly on the object the method returns the string value john. But what if we first store the reference to the getName object method in another variable by the name of fetchName and then call getName method indirectly by invoking its reference `fetchName`. In this case we get any an empty response. But why the does the indirect call does not work? This is because fetchName stores the reference to the object method and not the entire object, hence it will not be able to refer to the name property of the person object. In other words, its context is empty and does not have any property by the key as name.
#codinginterview #javascript #coding #softwaredevelopment


На этой странице сайта вы можете посмотреть видео онлайн JavaScript object method's this context | длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Mayank Srivastava 16 Апрель 2024, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 241 раз и оно понравилось 10 зрителям. Приятного просмотра!