Created
January 29, 2013 21:09
-
-
Save yangsu/4667892 to your computer and use it in GitHub Desktop.
JavaScript Function Invocation - Constructor
This file contains 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
// this refers to the newly created object returned by new | |
var Counter = function (init) { | |
this.value = init || 0; | |
} | |
Counter.prototype.increment = function (inc) { | |
inc = inc || 1; | |
this.value += inc; | |
} | |
var anotherObj = new Counter(); | |
var bad = Counter(); // Don't do this, value gets attached to the global object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment