Skip to content

Instantly share code, notes, and snippets.

@hitsujiwool
Created March 30, 2012 18:19
Show Gist options
  • Save hitsujiwool/2253663 to your computer and use it in GitHub Desktop.
Save hitsujiwool/2253663 to your computer and use it in GitHub Desktop.
What is 'this'
var foo = {
bar: function() {
console.log('this is ' + this.toString());
}
};
var baz = foo.bar;
foo.bar(); // thisはfoo
baz(); // thisはwindow
// 関数とメソッドの違いは定義のされ方ではなく、呼び出しの形式だよ
// http://jsfiddle.net/gh/gist/library/pure/2253663
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment