I have a Javascript class (using John Resig's approach) that I create an instance of and pass an args
object, like so:
var myCucumber = new Cucumber({
size: 'small'
organic: true
})
Within the class itself, it references many properties on the args
object. However none of the properties are meant to be mandatory, so there may be some missing ones at times, which causes "property is undefined" errors.
To remedy this, I do the following:
args.size = args.size || null;
args.organic = args.organic || false;
args.colour = args.colour || null;
args.origin = args.origin || null;
It seems kind of annoying to have to do this for each property that may get used throughout the class.
Is there a clean way to assume that any property of args will be null
if it hasn't been passed in when an instance of the class was created?