Skip to content

Instantly share code, notes, and snippets.

@beala
Last active December 14, 2015 11:08
Show Gist options
  • Select an option

  • Save beala/5077134 to your computer and use it in GitHub Desktop.

Select an option

Save beala/5077134 to your computer and use it in GitHub Desktop.
daily dose of js wat
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