Last active
December 14, 2015 11:08
-
-
Save beala/5077134 to your computer and use it in GitHub Desktop.
daily dose of js wat
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
| function C(a){ | |
| this.a = a | |
| this.f = function(){ print(this.a); }; | |
| } | |
| o = new C('racecar'); | |
| o.f() // prints 'racecar' | |
| a = o.f | |
| a() /* prints: | |
| * function () { | |
| * print(this.a); | |
| * } | |
| */ | |
| /* Yes, a() prints itself, because `this` in a's function body | |
| * references global. global.a is the function a, and not 'racecar'. | |
| * o.f isn't bound to its receiver (o) when it's assigned to a. | |
| * Because, JS. | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment