Skip to content

Instantly share code, notes, and snippets.

@conanak99
Last active Mar 9, 2016
Embed
What would you like to do?
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