Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I agree, but do all functions use 'this'?


No, and part of the reasoning is to explicitly avoid the chance you might accidentally refer to the wrong `this`. There's an ESLint rule to enforce this: it will complain if you use a `function` without referring to the prototype this. Makes it handy because if I do use `function` I know it's because there's a reason -- e.g. some libraries still make heavy use of the local this.

https://eslint.org/docs/rules/prefer-arrow-callback


The rule you link to is specific to "function expressions", which may or may not use 'this'.

To ask the same question differently, what about functions that do not need 'this'?


I'm not sure what your proposal is -- use functions that use prototype this or no this, and arrow functions for ones that use contextual this?

It's easier to use arrow functions for everything except for the tiny minority of cases where you want prototype this.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: