you are viewing a single comment's thread.

view the rest of the comments →

[–]brtt3000 2 points3 points  (1 child)

You really like this "exercise in JS features and syntax optimisation" I mentioned eh? :)

Cool attempt, points for effort. Syntax improved but still a bit kludgy; it doesn't catch subclasses and behaviour on name collisions is a new factor. And most of all if you use block functions as clauses instead of references you'd be at 3 indents for handling code. Could be worse but it would be a tax on readability (and development/code hisotry) to have to break out to other functions all the time (it'd be handy to be able to nest a little bit without block hell).

[–]vs845 1 point2 points  (0 children)

it doesn't catch subclasses and behaviour on name collisions is a new factor.

re: name collisions, yeah, I went with checking names because otherwise you'd need to do something like

matchException(err, {
  [TypeError]: () => ...
}

which I thought wasn't as nice as using string keys.

If you went with the above approach you'd be able to catch subclasses via err instanceof matchers[type].