Last active
August 29, 2015 14:22
-
-
Save JordanDelcros/0d44bb5ee1083f57a162 to your computer and use it in GitHub Desktop.
Elegant JavaScript Class creation
This file contains 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
/* | |
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