Last active
August 29, 2015 14:00
-
-
Save jussi-kalliokoski/11250536 to your computer and use it in GitHub Desktop.
Dealing with function function signatures with multiple arguments.
This file contains hidden or 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
// The usual way | |
var prepend = function (string, prefix) { | |
return prefix.concat(string); | |
}; | |
prepend("foo", "bar_"); // Wait, what? Is this "foobar_" or "bar_foo"? Not obvious without seeing the function signature. | |
// More natural language | |
var prepend = function (string) { | |
return { | |
with: function (prefix) { | |
return prefix.concat(string); | |
} | |
}; | |
}; | |
prepend("foo").with("bar_"); // "bar_foo" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment