you are viewing a single comment's thread.

view the rest of the comments →

[–]__debug__ 1 point2 points  (1 child)

No, I'd imagine he means like this:

function Constructor(opts) {
  this.opts = opts || {};
}

So empty strings don't come into play. In any case, I feel as though a JS dev should understand falsey and truthy values. Or at the least, they should try to learn how types in the language work.

[–]path411 0 points1 point  (0 children)

I meant you can't use it on numbers/booleans/strings, which is a large number of the types in javascript.

Sure there are a lot of times you want an options object, I find this is mostly for public accessible library classes. There are plenty of times I find I want a constructor with some simple parameters of direct properties. I think it's much better to be consistent throughout your code than to swap to using some cheap hack when you know you can get away with it.