-
-
Save conanak99/0485501d16c22d9ec127 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var person = { | |
firstName: 'Hoang', | |
friends : ['Minh', 'Sang', 'Khoa', 'Hoang'], | |
showFriend: function() { | |
this.friends.forEach(function(fr) { | |
// Với cách viết cũ, this ở đây sẽ là object window, không phải person | |
console.log(this.firstName + ' have a friend named ' + fr); | |
}); | |
// Ta sử dụng arrow, this vẫn là object person | |
this.friends.forEach(fr => console.log(this.firstName + ' have a friend named ' + fr)); | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment