My original post was a joke because 'this' is a context sensitive word in English and JavaScript.
Anyways, after thinking about this, the better questions are: When should I modify the scope vs passing a parameter? When should I use a decorator vs a callback? What is the best pattern for attaching behavior?
IMO this should not be used outside of classes since arrow functions exist and decorators should probably be preferred over callbacks for comparability purposes.
Unfortunately you cannot really see the benefit of decorators unless you use TypeScript.
Both snippets do the same thing. A function is evaluated if some path matches the request path. It all comes down to how/when the code should be accessible.
Although in typescript, you technically do not have to invoke a function, you have more control over data, and you can reuse the wrapper.
Thanks for your comment, appreciate it!
Actually the topic of my post is also valid for decorators syntax as anyway a decorator is a wrapper function and does not pass this inside a decorated function.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This becomes more important when you providing context to callbacks. No pun intended.
May you provide any simple example?
My original post was a joke because 'this' is a context sensitive word in English and JavaScript.
Anyways, after thinking about this, the better questions are: When should I modify the scope vs passing a parameter? When should I use a decorator vs a callback? What is the best pattern for attaching behavior?
IMO
this
should not be used outside of classes since arrow functions exist and decorators should probably be preferred over callbacks for comparability purposes.Unfortunately you cannot really see the benefit of decorators unless you use TypeScript.
Both snippets do the same thing. A function is evaluated if some path matches the request path. It all comes down to how/when the code should be accessible.
Although in typescript, you technically do not have to invoke a function, you have more control over data, and you can reuse the wrapper.
Thanks for your comment, appreciate it!
Actually the topic of my post is also valid for decorators syntax as anyway a decorator is a wrapper function and does not pass this inside a decorated function.