Skip to content

Instantly share code, notes, and snippets.

@masihyeganeh
Created August 15, 2012 20:02
Show Gist options
  • Save masihyeganeh/3363139 to your computer and use it in GitHub Desktop.
Save masihyeganeh/3363139 to your computer and use it in GitHub Desktop.
Template of an Object Oriented node.js module
var Class = (function Class() {
var singleton_private_variable = 'Singleton Private variable';
function singleton_private_function () {
return 'Private Function';
}
var Obj = {
singleton_public_variable: 'Singleton Public variable',
singleton_public_function: function() {
return 'This is Singleton Public method. it can access ' + singleton_private_variable + 's, '
+ this.singleton_public_variable + 's and ' + this.public_variable + 's.';
}
};
(function(){
console.log('Singleton Constructor');
})();
return Obj;
})();
module.exports = function() {
return Object.create(Class, (function(){
var private_variable = 'Private variable';
(function(){
console.log('Constructor');
})();
return {
public_variable: {
writable: true,
configurable: false,
enumerable: true,
value: "Public variable"
},
public_function: {
writable: false,
configurable: false,
enumerable: true,
value: function(){
return 'This is Public method. it can access ' + private_variable + 's, '
+ this.singleton_public_variable + 's and ' + this.public_variable + 's.';
}
}
};
})());
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment