This function has destructuring and the default parameters are mixed.
Based on the signature of the function, we can say that we expect one argument, which should be an object.
function list(myObject) { }
If the arguments are not passed (or passed undefined ), we set the default value as an empty object, {} .
function list(myObject = {}) { }
Now, regardless of whether we pass the object, no arguments or undefined , myObject will not.
// myObject will be {} for all 3 calls list({}) list() list(undefined);
Then we destroy this myObject , extracting skip and limit from it:
function list(myObject = {}) { let { skip, limit } = myObject; }
In addition, we can perform this destructuring directly instead of the myObject parameter:
function list({ skip, limit } = {}) { }
Finally, in case skip or limit does not exist in the value that we are ending, we give them the default values:
function list({ skip = 0, limit = 50 } = {}) { }
nem035
source share