Skip to content

Instantly share code, notes, and snippets.

@chemdemo
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chemdemo/9106001 to your computer and use it in GitHub Desktop.
Save chemdemo/9106001 to your computer and use it in GitHub Desktop.
`this` in javascript
// `this` in javascript functions points to the object called it!!
function f() {
undefined !== this.x ? this.x ++ : (this.x = 1);
}
var o = {
f: f
};
o.f();
o.f();
o.x; // => 2
f();
window.x; // => 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment