Try to search your question here, if you can't find : Ask Any Question Now ?

Create variable of arguments type

HomeCategory: stackoverflowCreate variable of arguments type
kundan asked 3 weeks ago

I’m trying to make middleware function lets call it debug, which should take some parameters, log them and pass to the next function:

const debug = (...args) => {
 console.log(...args)
 return args // will return array, not argument type variable
}

const compose = (...fns) => (...arg) => (
  fns.slice().reverse().reduce(
    (acc, fn) => !acc ? fn(...arg) : fn(acc), null
  )
)

const f = x => x * x

const g = (a, b) => a + b

const makeMagic = compose(
  f,
  g,
  debug
)

makeMagic(1, 2)

If I remove debug from composition everything works as expected, as soon as I place it at end, it breaks. Because it takes arguments but returns array.

I tried to rewrite debug this way:

function debug() {
  console.info(arguments)
  return arguments
}

But no way it fails.

1 Answers
Best Answer
Mikhail answered 3 weeks ago
Your Answer

1 + 15 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com