Created
March 30, 2012 18:19
-
-
Save hitsujiwool/2253663 to your computer and use it in GitHub Desktop.
What is 'this'
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 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