3 ms·
Yeah, you can write it in less than a minute: const tryNew = (f, ...a) => { try { return new f(...a); } catch(x) { return undefined; } }; c
by RaisingSpear 2y ago
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/ 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.
- hyperhopper 2y agoIronic since your snippet is now a new leftpad. Does every dev need to write the same line now? Or should your one-liner be a library? The basics that everybody needs, should be standardized in the standard library.
- RaisingSpear 2y ago> Does every dev need to write the same line now? Yes. > Or should your one-liner be a library? Definitely not. Particularly if I can write the one-liner faster than it takes one to search, check, include and install the library.