Created
August 15, 2012 20:02
-
-
Save masihyeganeh/3363139 to your computer and use it in GitHub Desktop.
Template of an Object Oriented node.js module
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
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