I'd like to use named parameters (simulated via object literals) in my JavaScript functions for ease of readability. The code I've written works fine when I explicitly pass my parameters, but I'm having trouble trying to set a default value, so that my function can be called not only via as myFunction({someBoolean:true}) OR as myFunction() which would imply a default of someBoolean:false.
myFunction: function({myArgs}){
myArgs.someBoolean = myArgs.someBoolean || false;
if (myArgs.someBoolean) {
[do stuff]
}
[do other stuff]
},
This works fine when I call myFunction({someBoolean:true}), but when I call myFunction(), I get "Uncaught TypeError: Cannot read property 'someBoolean' of undefined."
Thanks in advance!