Skip to content

Instantly share code, notes, and snippets.

@eiszfuchs
Created October 21, 2014 13:06
Show Gist options
  • Select an option

  • Save eiszfuchs/ba358a5c5e0c59e4c44b to your computer and use it in GitHub Desktop.

Select an option

Save eiszfuchs/ba358a5c5e0c59e4c44b to your computer and use it in GitHub Desktop.
(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