+ 1
if we call the getName function in an sebuahobjeklain, we will get an undefined output. What's wrong ? And how to fix it ?
const sebuahObjectLain = { name: 'Bejo Jhonson', getName: () => this.name }
3 Antworten
+ 5
We cannot use 'this' when using arrow functions.
Solutions:
const sebuahObjectLain = {
name: 'Bejo Jhonson',
getName: function(){
return this.name;
}
}
//Ecmascript6:
const sebuahObjectLain = {
name: 'Bejo Jhonson',
getName(){
return this.name;
}
}
+ 2
Hi post your code in description part not in question title ,it has limited words and therefore your code is cut
+ 1
Febriantika Triarini
When using this in arrow function, this refeers to global object. Here you have not defined name in the global object.