Search code examples
javascriptarrow-functions

Does Arrow Functions in JS also inherit the Function() prototype?


Given the risk of prototype-pollution in JavaScript,

In case I can't freeze/seal the built-in Function()'s prototype, or some of it's parents in the prototype-chain (eg Object()'s),

can I use arrow-functions, in order to guarantee it's execution/calls to be straight-forward, without the chance for Proxy()'ies, side-effects of hooks, or any other kind of manipulation possible due to pollution of regular functions?

From this SO answer (which was marked as a forwarding answer to a duplicated question to mine, that has no answer) I can't understand if it's guaranteed that arrow-functions are not prototyped, by standard or by de-facto implementations.

In Mozilla's MDN page, I found no mentions to a prototype of Arrow-Functions.

My goal is to restrict some critical logic, to make its execution safe from any possible modification, differing, injected side-effects, monitoring, wrapping, triggering of events, and more. * (And maybe even debugging, if possible, but it's maybe for another question).


Solution

  • Yes, it does and it's easy to check:

    const boo = () => {};
    
    function hoo() {}
    
    console.log(Object.getPrototypeOf(boo) === Object.getPrototypeOf(hoo)); // true