I'd like `throw` expressions (a lot). I wouldn't use them for this, but I
want them for many of the same reasons outlined in the C# case for them.
-- T.J. Crowder
On Wed, Apr 12, 2017 at 1:10 AM, Ron Buckton
wrote:
> I’d much rather see something more like C# 7’s
Maybe every operator can have a non-coercing variant?
One possible syntax is to have a modifier on operators
x = a (<) b (+) c (&&) (!)d;
if (x (!=) y) ...
Another possible syntax is to have a modifier on expressions
x = #(a < b + c && !d)
if #(x != y) ...
On Tue, Apr 11, 2017
Although I’m unsure if this is wise given there are already eleven symbols
that are combinations of `=` and `<`/`>`, for symmetry with `==` and `===`
I’d imagine something like this:
```
COERCIVE STRICT
> =>=
< =<=
>==>==
<==<==
```
Could also follow the pattern
I’d much rather see something more like C# 7’s throw expressions:
https://docs.microsoft.com/en-us/dotnet/articles/csharp/whats-new/csharp-7#throw-expressions
```js
// original example
fs.writeFile("message.txt", "Hello Node.js", err => err ? throw err :
console.log("The file has been saved.");
It's definitely an interesting idea... Been trying to consider what
character would be added to represent a strict comparison... Perhaps @?
>@ <@ <=@ >=@ ...
Not sure how this might conflict with decorators...
--
Michael J. Ryan - track...@gmail.com - http://tracker1.info
Please excuse
Thanks for explaining, Michael. That does make sense, there are indeed
plenty of places where such distinctions must be made for syntactic
productions. I’m not sure why I was assumed the lexical grammar was special
in this regard; it just happens to be that the only other similar case has
the
I don't think we need a new keyword for this, both because of Elie's point
about handling it with a `throwif` function, and because Node's callback
pattern is a bit old-fashioned in the world of promises and async/await.
Until the Node API is updated to support promises natively, you can use one
const throwIf = (fn) => (err, ...args) => {
if(err) throw err;
return fn(...args);
};
...
fs.writeFile('message.txt', 'Hello Node.js', throwIf(() => console.log('The
file has been saved')));
No need to extend the language and preempt keywords with stuff you can very
easily implement in
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
9 matches
Mail list logo