I'm learning generator functions in the codebase (redux sagas) and I'm seeing parameters passed in like
export function* someGenerator({ x, y = {} }) {
when I run it like
someGenerator('xyz', 'abc')
as with a regular function it comes out as undefined
I don't get the ({}) part or how I can pass a parameter into such a function.
thing is I'm trying to call a generator function within another one
The function is using Default Object properties. It is doing two things:
x if the object with property x is provided to the function as first argument.y of the given object. If there is not property y of the parameter then it will be assigned to empty object.See the below examples:
function someGenerator({ x, y = {} }) {
console.log(x)
console.log(y)
}
someGenerator({x:'xyz',y:'abc'})
someGenerator({x:'xyz'}) // 'y' will empty object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With