0

Pretty self explanatory, is there a way to check, in code, the difference between an arrow function an a regular one?

Explaining myself:

I have an array of functions coming in, most are simple arrow functions that return an object, but the rest are regular functions, used as constructors. Is there a way to check whether a function is an arrow or not without being horribly inefficient with pak.map(el => {try {el.unpak = new el.fn} catch(e) {el.unpak = el.fn()}})? The try/catch is an idea I came up with that works, but is horridly slow (since only a handful of functions are actually constructors in this array) and really refuse to use that in any production scenario. Does anyone have any ideas to this?

Werlious
  • 583
  • 6
  • 15
  • Where does this array come from? Can't you just wrap the constructors with something like this: `const makeCallable = constructor => () => new constructor();` checking in the console, it seems that arrow functions have no `prototype` object, but I don't know wether this is reliable or just a chrome thing. – Thomas Jul 08 '20 at 06:25
  • Unfortunately, I have no control over that, the array comes from an ABI call. But I guess its a dup anyway lol – Werlious Jul 08 '20 at 07:48

0 Answers0