Skip to content

Instantly share code, notes, and snippets.

@frekw
Created July 16, 2010 13:33
Show Gist options
  • Save frekw/478367 to your computer and use it in GitHub Desktop.
Save frekw/478367 to your computer and use it in GitHub Desktop.
Function.prototype.curry = function() {
var fn = this, args = Array.prototype.slice.call(arguments);
return function() {
return fn.apply(this, args.concat(
Array.prototype.slice.call(arguments)));
};
};
var YES = true,
NO = false;
var Controller = {
render: function(template){},
validate: function(data){},
handler: function(isPost, request, response, params){
if(isPost) this.validate(params);
this.render("template.ext");
}
}
app.route = function(url, handler){
this['get'].call(this, [url, handler.curry(NO)]);
this['post'].call(this, [url, handler.curry(YES)]);
}
app.route('/', Controller.handler);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment