Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var person = {
firstName: 'Hoang',
lastName: 'Pham',
friends : ['Minh', 'Sang', 'Khoa', 'Hoang'],
showFriend: function() {
for(var i = 0; i < this.friends.length; i++)
console.log(this.firstName + ' have a friend named ' + this.friends[i]);
},
showFriendThis: function() {
this.friends.forEach(function(fr){
console.log(this.firstName + ' have a friend named ' + fr);
});
}
};
person.showFriend(); //Hàm chạy đúng
person.showFriendThis(); // Hàm chạy sai
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.