Skip to content

Instantly share code, notes, and snippets.

@theleoborges
Forked from boundvariable/gist:1685985
Created January 27, 2012 00:42
Show Gist options
  • Save theleoborges/1686173 to your computer and use it in GitHub Desktop.
Save theleoborges/1686173 to your computer and use it in GitHub Desktop.
Chapter 5 example
//I guess I'd go with straight functions into a module you could mixin or use directly OR objects...
//On the first option, something like this:
var app = app || {};
app.server = app.server || {};
app.server.http = function() {...};
app.server.get = function() {...};
app.server.post = function() {...};
//And for the second option:
var app = app || {};
app.server = function() {
that = {};
that.http = function() {...};
that.get = function() {...};
that.post = function() {...};
return that;
}();
// I personally prefer the latter. But just because it gives you a chance of having privacy across the
// server object.
// However, being just a collection of functions, the first could work just as well.
// All in all you're dealing with objects anyway, just creating them differently.
// Either way, I don't think I'd use classes.
// But that's me talking about straight JS. Maybe it'd make sense in CoffeeScript,
// given people are usually not familiar with FP. - I wasn't until recently ;)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment