Skip to content

Instantly share code, notes, and snippets.

@emkay
Created November 14, 2011 02:19
Show Gist options
  • Select an option

  • Save emkay/1363087 to your computer and use it in GitHub Desktop.

Select an option

Save emkay/1363087 to your computer and use it in GitHub Desktop.
Functions as Methods
var counter = {
value: 0,
increment: function () {
this.value += 1;
},
reset: function () {
this.value = 0;
}
};
console.log(counter.value); // 0
counter.increment();
counter.increment();
counter.increment();
console.log(counter.value); // 3
counter.reset();
console.log(counter.value); // 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment