Skip to content

Instantly share code, notes, and snippets.

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.

Motivation

  • 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/or this
    • deliberately trying to avoid function genericism
    • trying to improve consistency of style
  • 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