0đź‘Ť
âś…
Javascript does not look for a property that defined before, to set a value. It finds the object and sets the value. If there’s no such property, it creates.
On the other hand, it also matters how you define the function for what “this” means. I’ll give an example on a Vue component data object:
data() {
return {
first_object: {
action() {
// "this" refers to first_object
}
},
second_object: {
action: () => {
// "this" refers to Vue instance
}
},
};
}
I hope this explanation helps.
Source:stackexchange.com