Almuntasir Abir
Almuntasir Abir

Reputation: 318

having a problem with this piece of javascript code

Let's suppose actions is defined but how do I access this first and second boolean inside someFunction?

is this an object or some kind of destructuring? cause I am getting a some kind of destructuring error.

function someFunction(actions, { first = true, second= false }) {      
    if(first == true) {
      console.log("something");
    }
}   
  

Error i get -

TypeError: Cannot read property 'first ' of undefined

Upvotes: 0

Views: 85

Answers (1)

Stephen P
Stephen P

Reputation: 14800

For that to work you have to pass a second parameter when you call the function.
The second argument will be destructured; delayedActions("foo", "bar") will work, but delayedActions("foo", {}) makes more sense.

You can override the default value of recursive:
delayedActions("foo", { recursive:false })

The object parameter can include other things not in the function signature object:
delayedActions("foo", { recursive:true, errorExit:true, fooParam:'bar' })

Without a second parameter you get an error such as
VM48976:1 Uncaught TypeError: Cannot read property 'recursive' of undefined

Upvotes: 1

Related Questions