Created
October 3, 2012 04:48
-
-
Save colbyr/3825058 to your computer and use it in GitHub Desktop.
Make a class in a module
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
/** | |
* use underscore js because its useful | |
*/ | |
var _ = require('underscore'); | |
/** | |
* Constructor -- `new Class('frosted')` | |
*/ | |
function Class(prop) { | |
this.prop = prop; | |
} | |
/** | |
* this method won't be visible outside this file | |
*/ | |
function _privateMethod(param) { | |
return param + ' butts'; | |
} | |
/** | |
* add some instance methods to the prototype | |
*/ | |
_.extend(Class.prototype, { | |
/** | |
* accessible via `new Class('frosted').method()` | |
*/ | |
method: function () { | |
return _privateMethod(this.prop); | |
} | |
}); | |
/** | |
* add some static methods to the class | |
*/ | |
_.extend(Class, { | |
/** | |
* accessible via `Class.static_method()` | |
*/ | |
static_method: function (param) { | |
return _privateMethod(param); | |
} | |
}); | |
/** | |
* export the constructor function | |
*/ | |
exports = Class; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment