Created
November 4, 2016 01:22
-
-
Save ariellephan/cf6d61f2418d10d259a2d249a33b88c8 to your computer and use it in GitHub Desktop.
Currying - functional js
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
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