Skip to content

decontextify

Subhajit Sahu edited this page Aug 7, 2022 · 1 revision

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

Similar: contextify, decontextify.


function decontextify(x)
// x: a function

const xasyncfn = require('extra-async-function');


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

var fn = xasyncfn.decontextify(count);

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

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