JavaScript call and apply methods in action

Publicado em: 20 April 2024
no canal de: Mayank
292
9

In this code snippet, you have an object named person with two properties:
name: It holds the value "john".
getName: It's a function that returns the name property of the person object using this.
Next, you declare a variable fetchName and assign the getName method of the person object to it.

Finally, you call fetchName().

However, there's a caveat here: when fetchName is called, it's no longer associated with the person object. So, the this keyword inside fetchName doesn't refer to the person object anymore. Instead, it refers to the global object (in non-strict mode) or undefined (in strict mode). Since the global object (or undefined in strict mode) doesn't have a name property, calling fetchName() will likely result in an error or undefined being returned.


Nesta página do site você pode assistir ao vídeo on-line JavaScript call and apply methods in action duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Mayank 20 April 2024, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 292 vezes e gostou 9 espectadores. Boa visualização!