Skip to content

decontextify

Subhajit Sahu edited this page Jul 22, 2022 · 2 revisions

Decontextify a function by accepting this-object as the first argument.

Similar: [contextify], decontextify.


function decontextify(x)
// x: a function

const {decontextify} = require('extra-function');


function count(value) {
  var a = 0;
  for (var v of this)
    if (v===value) ++a;
  return a;
}

var fn = decontextify(count);

fn([6, 3, 4, 3], 3);
// → 2

fn([6, 1, 4, 3], 3);
// → 1
Clone this wiki locally