Skip to content

Default options argument in initializers

Compare
Choose a tag to compare
@koresar koresar released this 02 Jun 06:50
· 38 commits to master since this release

In this release the initializers won't need to check if the option argument was passed:

const MyStamp = compose({initializers: [
  function (options = {}) { // <-- not needed any more
    console.log(options.opt1); // used to throw here
  }
]});

The line below will just work now.

const MyStamp = compose({initializers: [
  function (options) {
    console.log(options.opt1); // used to throw here
  }
]});
MyStamp();

Previously it was throwing. So that you always had to pass an empty object:

MyStamp({});

Although, this won't save you from the following:

MyStamp(null); // will throw regardless
MyStamp(42); // will throw regardless