0

I'm trying to init my parameters so I can run getProducts(), as well as

getProducts({
  query: {},
  p: {
    offset: 0,
    sort: {
      _id: 1
    },
    limit: 25,
    count: 0
  }
})

. So far, only the latter works, using this function :

getProducts({
  query = {},
  pagination: {
    offset = 0,
    sort = {
      _id: 1
    },
    limit = 25
  }
}) {
  console.log(offset, limit, sort)
}

I'm pretty sure I'm missing something simple on initialisation, but can't figure out what, even with the MDN docs.

2
  • "The latter works" what works exactly? Because nothing in your code is working... The console.log closed with brace instead of parentheses, is it a function declaration because it got no Function keyword. It also cannot be a call, since it has braces after... Please show us the right defintion, the way you call it when it works, the way you call it when it does not. Commented Sep 18, 2017 at 11:46
  • ugh, sth went wrong with the auto indent, fixed Commented Sep 19, 2017 at 11:50

1 Answer 1

1

Your code is not following the Object destructuring syntax as you can see here, check this:

function getProducts({query, pagination: {offset, limit, sort}} = {query: {},pagination: {offset: 0, limit: 25, sort: {_id: 1}}}){
  console.log(query, offset, limit, sort);
}

getProducts()

getProducts({query: {}, pagination: {offset: 10, limit: 50, sort: {_id: -1}}})

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.