Last active
August 29, 2015 14:04
-
-
Save owskio/8c3b2511fde46a41e69a to your computer and use it in GitHub Desktop.
Combinator Use Case: Adding AJAX Defaults
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
// ... | |
//AJAX DEFAULTS | |
basicAjax = addDefaults($.ajax,{ | |
type: "GET", | |
dataType: 'json', | |
contentType: 'application/json', | |
error: function (jqXHR,textStatus,errorThrown) { | |
/* do some default error handling */ | |
} | |
}), | |
//... | |
alter = function (o,k,f) { | |
o[k] = f(o[k]); | |
return o; | |
}, | |
alterThe = curry3(counterClock(alter)), | |
//... | |
ajax = chain( | |
//Don't forget our blessed ASP.NET virtual | |
//path which changes all the friggin time | |
alterThe('url',function(u){ | |
return util.virt(u); | |
}), | |
//Or simply: | |
//alterThe('url',util.virt), | |
basicAjax | |
), | |
//... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We can use simple combinators to add default arguments to functions which take single objects as argument collections, or later, we can use simple combinators to alter the functionality of our functions by prefixing argument-object mutators.