a function parameter does? E.g a function getList(optParameter) and I want to add a parameter that returns a somewhat different list. so in the call it could end up being getList(true) which is horrible since there's no way to tell what true parameter does. config obj?
Sounds like you want a second function
Create a const for the boolean parameter: const includeDates = true; const result = getList(includeDates) Also, use JS Docs to make it clear what a parameter does. Another option is making a "private" function that takes the parameter, and other two "public" functions that handles that paramater: /** * @param { boolean | undefined } includeDates description */ function getList(includeDates) { ... } function getListWithDates() { return getList(true); } function getListWithoutDates() { return getList() }
forgot to thank you btw, that's a good solution
Обсуждают сегодня