- Partial application is fundamental to functional-style programming
- It is the binding of arguments to parameters before a function is invoked
- This technique is often used by ECMAScript developers who are:
- seeking to avoid the use of
new
and/orthis
- deliberately trying to avoid function genericism
- trying to improve consistency of style
- seeking to avoid the use of
- Partial application is currently supported by
Function.prototype.bind
, but the syntax is verbose, and the target of the bound function comes first, diluting the semantic - Writing a custom function to provide partial application is straightforward (indeed there are many open source libraries providing this such as
_.partial
), however developers taking this approach are constrained in their ability to achieve syntactic tenseness lest they surprise other developers - A terse, native syntax for partial application that does not affect the target of a function will improve consistency, clarity of intent and legibility
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
var need = require('niid').need; | |
var mix = require('mixx').mix; | |
var defaultOptions = Object.freeze({ foo: undefined, | |
bar: undefined, | |
bam: null, | |
baz: null }); | |
function MyThing(options) { | |
need(options, 'foo', 'bar'); // `foo` and `bar` are required. |
OlderNewer