Last active
December 2, 2015 06:04
-
-
Save mitsuru793/bd548c802340c304cfc1 to your computer and use it in GitHub Desktop.
JavaScriptでnewを付けない関数だと、thisはグローバルオブジェクトになる。
This file contains hidden or 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
| // console.logのエイリアス | |
| var l = function(x) { console.log(x) }; | |
| function Person(name) { | |
| l(this); | |
| this.name = name | |
| } | |
| Person("田中"); // Window | |
| l(name); // 田中 | |
| l(this); // Window | |
| l(this.name); // 田中 | |
| l("--suzuk--") | |
| suzuki = new Person("鈴木"); // Person {} | |
| l(suzuki.name); // 鈴木 | |
| l(name); // 田中 | |
| l(this); // Window | |
| l(this.name); // 田中 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment