Skip to content

Instantly share code, notes, and snippets.

@specialunderwear
Created January 30, 2012 00:11
Show Gist options
  • Save specialunderwear/1701513 to your computer and use it in GitHub Desktop.
Save specialunderwear/1701513 to your computer and use it in GitHub Desktop.
constructor defines methods
> var Counter = function(from) {
> this.from = from;
> this.next = function() {
> this.from += 1;
> return this.from;
> };
> }
> var count_from_7 = new Counter(7);
> var count_from_3 = new Counter(3);
> count_from_7.next();
8
> count_from_3.next();
4
> count_from_7.next();
9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment