Skip to content

Instantly share code, notes, and snippets.

@JordanDelcros
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JordanDelcros/0d44bb5ee1083f57a162 to your computer and use it in GitHub Desktop.
Save JordanDelcros/0d44bb5ee1083f57a162 to your computer and use it in GitHub Desktop.
Elegant JavaScript Class creation
/*
Must easy and elegant way to create classes or complex objects in JavaScript
*/
(function( window, document ){
function Class( options ){
if( this instanceof Class ){
return Class.fn.init(options);
}
else {
return new Class.fn.init(options);
};
};
Class.fn = Class.prototype = {
constructor: Class,
init: function( options ){
return this;
},
myMethodA: function(){},
myMethodB: function(){}
};
Class.fn.init.prototype = Class.fn;
window.Class = Class;
})(window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment