Skip to content

Instantly share code, notes, and snippets.

@conanak99
Last active February 2, 2016 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conanak99/8d35e3eadc671c728aac to your computer and use it in GitHub Desktop.
Save conanak99/8d35e3eadc671c728aac to your computer and use it in GitHub Desktop.
var person = {
firstName: 'Hoang',
lastName: 'Pham',
showName: function() {
console.log(this.firstName + ' ' + this.lastName);
}
};
//showName truyền vào như callback, ở đây this chính là button
$('button').click(person.showName);
// Dùng bind để xác định giá trị this
$('button').click(person.showName.bind(person)); //this ở đây vẫn là object person
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment