Comment

Comment by RaisingSpear

Yeah, you can write it in less than a minute:

const tryNew = (f, ...a) => {

  try {

   return new f(...a);

  } catch(x) {

   return undefined;

  }

 };
const myUrl = tryNew(URL, 'http://example.com/');

I don't get why JS devs like to whinge about the smallest things. And we get stuff like leftPad because of huge aversion to writing utility functions.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton