I have an overloaded toggle function and want to document the behaviors w/ JSDoc.
If the value is defined the window state is set to the boolean value of the truthy parameter, if undefined the window state toggles. I'm looking for something like this.
/**
* Set the map window in mobile
* @param {undefined|*} on - toggle or set the window state
* - {undefined} toggles window state
* - {*} set window state
*/
toggleWindow(on) {
if (on === undefined) {
on = !this.state.window;
}
this.setState({ mapWindow: !!on });
}
toggleWindow
as a function taking no parameters and then moved the other functionality into something likesetWindow
.on=!this.state.window
isn't a bad idea since default parameters are re-evaluated at "call time" Even though it doesn't directly answer the question, such an answer should earn you some upvotes.