parapply

Partial function application.

Usage no npm install needed!

<script type="module">
  import parapply from 'https://cdn.skypack.dev/parapply';
</script>

README

parapply

Partial function application for javascript.

Usage

This is partial function application alright. Different from other packages though, the functions here operate on the this scope and do not take the function as a parameter. This may sound weird at first, but it allows for more flexibility in usage. Observe:

var parapply = require("parapply");

// Our simple, trusty test function.
function add(a, b, c) {
  return a + b + c;
}

// To use, call or apply is needed.
var add1 = parapply.call(add, 1);

// Being able to use apply allows us to pass arrays too!
var add1_2 = parapply.apply(add, [1, 2]);

// You could also add it to some prototype:
var proto = function () {};
proto.parapply = parapply;

Object.setPrototypeOf(add, proto);
var add1 = add.parapply(1);

// Or - if you feel save doing so - also to the Function prototype
Function.prototype.parapply = parapply;
var add1 = add.parapply(1);

To be continued.