Skip to content

Instantly share code, notes, and snippets.

@ariellephan
Created November 4, 2016 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ariellephan/cf6d61f2418d10d259a2d249a33b88c8 to your computer and use it in GitHub Desktop.
Save ariellephan/cf6d61f2418d10d259a2d249a33b88c8 to your computer and use it in GitHub Desktop.
Currying - functional js
var curryIt = function(uncurried) {
var parameters = Array.prototype.slice.call(arguments, 1);
return function() {
return uncurried.apply(this, parameters.concat(
Array.prototype.slice.call(arguments, 0)
));
};
};
var prefixModifier = function(prefix, connector, name) {
console.log(prefix + connector + name);
};
var prefixNamespace = curryIt(prefixModifier, "js", "-");
var prefixEl = curryIt(prefixModifier, "parentEl", "__");
prefixNamespace("counter");
prefixEl('counter');
var suffixModifier = function(suffix, connector, name) {
console.log(name + connector + suffix);
};
var suffixEnabled = curryIt(suffixModifier, "enabled", "--");
var suffixDisabled = curryIt(suffixModifier, "disabled", "--");
var suffixEl = curryIt(suffixModifier, "childEl", "__");
suffixEnabled("class");
suffixDisabled("class");
suffixEl("class");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment