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. parent RaisingSpear 2 years ago
const tryNew = (f, ...a) => {
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.