question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

prefer-arrow-callback: allowUnboundThis description may be confusing

See original GitHub issue

http://eslint.org/docs/rules/prefer-arrow-callback#allowunboundthis

I’ve read this paragraph several times and by comparison with the code example it seems a bit confusing:

  1. “When set to false, this option allows the use of this without restriction…”: does not the option apply more restrictions for using this?

  2. “…checks for dynamically assigned this values…”: does “checks” mean “prohibits” or “allows”?

  3. “Normally, the rule will flag…”: does “Normally” mean “true” or “false” for this option?

The code example is clear, but the description seems to be vague.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
not-an-aardvarkcommented, Jul 16, 2017

Thanks for reporting, I agree that the documentation is unclear/misleading here. To answer your questions:

  • The default behavior is {allowUnboundThis: true}. With the default behavior, the rule allows function expressions containing this, provided that they are not explicitly bound. This is because these functions would not be directly replaceable with arrow functions.

    foo(function() { this; }) // allowed by default
    foo(function() { this; }.bind(this)) // disallowed
    
  • When allowUnboundThis is set to false, the rule imposes a stricter requirement by disallowing all function expressions containing this, even though those functions are not directly replaceable with arrow functions.

0reactions
webdevdaemoncommented, Aug 5, 2017

I just realized that i PR’d 4 commits rather than just one… I’m sure you’ll let me know if I need to fix that…

1000 apologies.

PR submitted though!

Read more comments on GitHub >

github_iconTop Results From Across the Web

prefer-arrow-callback - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
prefer-arrow-callback
Allows function expressions containing this to be used as callbacks, as long as the function in question has not been explicitly bound. Rule...
Read more >
Avoid 'unbound function' ESLint warning when passing a ...
I am confused as to why ESLint warns me about the static function as it has no "this" at all. What can I...
Read more >
Sound Typing for “this” in Flow
Similarly, in the below code, Flow would allow you to call the exported ... like arrow functions and classes that discourage its use....
Read more >
arrow function syntax simplified
Use => only with an expression body (do-expressions if accepted allow ... We don't need thin arrow and we really don't need the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found