Re: Re: throwif operator

2017-04-12 Thread Нурбек
Yes, throw expressions would be helpful to shorten if statements to
one-liner ternary operators. I agree with you.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


throwif operator

2017-04-11 Thread Нурбек
An example from node.js documentation:

fs.writeFile('message.txt', 'Hello Node.js', (err) => {
  if (err) throw err;
  console.log('The file has been saved!');
});

This looks like a common way to handle errors when the first parameter is
an instance of Error.

Yes, this line of code is short and easy to copy-paste.
But introducing something like this:

fs.writeFile('message.txt', 'Hello Node.js', (err) => {
  throwif err;
  console.log('The file has been saved!');
});

would make the code much cleaner and bring some sort of standart way to
handle such errors.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss