Created
January 31, 2011 07:24
-
-
Save Nutrox/803735 to your computer and use it in GitHub Desktop.
JavaScript - Private/Static Property Example
This file contains hidden or 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
function Class() { | |
} | |
Class.prototype = new function() { | |
var value = 100; | |
function getValue() { | |
return value++; | |
} | |
this.getValue = getValue; | |
} | |
var a = new Class(); | |
var b = new Class(); | |
var c = new Class(); | |
console.log( a.getValue() ); // 100 | |
console.log( b.getValue() ); // 101 | |
console.log( c.getValue() ); // 102 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I agree that inheritance would be a problem in this situation, but it's just a little example. JavaScript prototype inheritance is a nasty thing to work with anyway, I avoid it whenever possible :)