Created
October 21, 2014 13:06
-
-
Save eiszfuchs/ba358a5c5e0c59e4c44b to your computer and use it in GitHub Desktop.
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 (scope) { | |
| var privateStaticProperty = null; | |
| var privateStaticMethod = function () { | |
| console.log("private hello"); | |
| }; | |
| var PublicClass = function () { | |
| var self = this; | |
| var privateProperty = null; | |
| var privateMethod = function () { | |
| }; | |
| self.publicProperty = null; | |
| self.publicMethod = function () { | |
| console.log("public hello: " + self.publicProperty); | |
| }; | |
| // do something here (constructor) | |
| privateStaticMethod(); | |
| return self; | |
| }; | |
| // demo method | |
| PublicClass.prototype.getPrivateStaticProperty = function () { | |
| return privateStaticProperty; | |
| }; | |
| // demo method | |
| PublicClass.prototype.setPrivateStaticProperty = function (value) { | |
| privateStaticProperty = value; | |
| }; | |
| scope.PublicClass = PublicClass; | |
| }).call(this, global); // `global` is for NodeJS | |
| // Here starts the demo | |
| var foo = new PublicClass(); | |
| var bar = new PublicClass(); | |
| console.log(foo.getPrivateStaticProperty()); | |
| console.log(bar.getPrivateStaticProperty()); | |
| foo.setPrivateStaticProperty("hello world"); | |
| console.log(foo.getPrivateStaticProperty()); | |
| console.log(bar.getPrivateStaticProperty()); | |
| foo.publicProperty = 1; | |
| bar.publicProperty = 2; | |
| foo.publicMethod(); | |
| bar.publicMethod(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment