Created
October 16, 2012 19:42
-
-
Save KylePDavis/3901504 to your computer and use it in GitHub Desktop.
JavaScript Classes Template (with proper inheritance)
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
//NOTE: if not in Node.js then you'll need to remove references to module.exports and require() | |
var MyClassName = (function(){ | |
// CONSTRUCTOR | |
var klass = module.exports = MyClassName = function MyClassName(){ | |
//[CONSTRUCTOR]; e.g., if(arguments.length > 0) throw new Error("Unexpected args!"); | |
//[INSTANCE MEMBERS]; e.g., this.value = 123; | |
base.call(this); | |
}, base = require("./BaseClass"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}}); | |
// PRIVATE STATIC MEMBERS | |
//[PRIVATE SCOPE]; e.g., var UtilsClass = require("./UtilsClass"); | |
// STATIC MEMBERS | |
//[KLASS PROPERTIES]; e.g., klass.getThing = function getThing(){ }; | |
// PROTOTYPE INSTANCE MEMBERS | |
//[PROTO PROPERTIES]; e.g., proto.doStuff = function doStuff(){ }; | |
return klass; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment