const user = {
name:'mdv',
places : ['rio', 'new', 'aust'],
printPlacesLived: function () {
return this.places.map((place)=>this.name +'has lived in '+place)
}
}
**this refers to the context in which they were created in ** (according to my knowledge)
2) so that is why inside my anonymous function this.name is working correctly
const user = {
name:'mdv',
places : ['rio', 'new', 'aust'],
printPlacesLived: () =>{
return this.places.map((place)=>this.name +'has lived in '+place)
}
}
Same method i have changed printPlacesLived to the arrow funtion so according to the defination
this refers to the context in which they were created in
1) Now i am getting places undefined if the definition is correct, printPlacesLived is created inside my user object so the refrence must be to places but not happening why ?
2) I am confused i studied some other definitions of arrow functions and this(it is mentioned that this retains the value of the enclosing lexical context's )
Now for printPlacesLived lexical context is name and places plese help me where did i go wrong