Skip to content

Instantly share code, notes, and snippets.



Created Nov 13, 2013
What would you like to do?
Mimic Java classes using closures and object properties.
var Class =
// Create a closure with an Immediately-Invoked Function Expression (IIFE)
(function () {
(function _init() {
// Similar to a static initializer in Java
// This is optional, but it prevents polluting the Class scope.
// Private static variable
var _static;
// Public static variable
function Class(arguments) {
// Private instance variable
var _instance;
// Public instance variable
// Publicly expose the Class constructor
return Class;
// Create an instance of Class
var object = new Class();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment