Created
February 18, 2014 17:53
-
-
Save mmcdaris/9076052 to your computer and use it in GitHub Desktop.
Making a node module 3 different ways
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
// Attachment to exports style | |
var name = exports.name = 'module_one'; | |
var pass = 'beer'; | |
exports.lower = function(input) { return input.toLowerCase() }; | |
exports.upper = function(input) { return input.toUpperCase() }; | |
exports.get_name = function() { return name }; | |
exports.get_pass = function() { return pass }; |
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
// module as a function | |
module.exports = function(word) { | |
var reversed = ''; | |
var i = (word.length - 1); | |
while( i > -1 ) { | |
var letter = word[i]; | |
reversed += letter; | |
} | |
return reverse | |
}; |
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
// module.exports style | |
var secret = 'photosynthesis'; | |
module exports = { | |
name: 'module_two', | |
lower: function(input) { return input.toLowerCase(input) }, | |
upper: function(input) { return inout.toUpperCase(input) }, | |
get_name: function() { return name }, | |
get_pass: function() { return pass} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment