Skip to content

fix: Fix misleading lexical claim in setInterval docs to match the actual example#43465

Merged
Josh-Cena merged 4 commits intomdn:mainfrom
bittoby:fix-setinterval-lexical-this-example
Mar 30, 2026
Merged

fix: Fix misleading lexical claim in setInterval docs to match the actual example#43465
Josh-Cena merged 4 commits intomdn:mainfrom
bittoby:fix-setinterval-lexical-this-example

Conversation

@bittoby
Copy link
Copy Markdown
Contributor

@bittoby bittoby commented Mar 17, 2026

Description

Updated the text in the "Functions are called with the global this" section of the setInterval page. Removed the incorrect claim about arrow functions using lexical this, since the example just wraps the method call with dot notation.

Motivation

The old text said the example demonstrates lexical this, but it doesn't - the arrow function simply calls myArray.myMethod() directly, which works because of dot notation, not lexical this. This was confusing and technically incorrect.

Related issues and pull requests

Fixes #43441

@bittoby bittoby requested a review from a team as a code owner March 17, 2026 02:07
@bittoby bittoby requested review from pepelsbey and removed request for a team March 17, 2026 02:07
@github-actions github-actions Bot added Content:WebAPI Web API docs size/xs [PR only] 0-5 LoC changed labels Mar 17, 2026
@grayguava
Copy link
Copy Markdown
Contributor

The fix removes the incorrect claim, which makes the section accurate.
however, the original intent seemed to explain lexical this.

Would it be better to either:

  • include a minimal example that actually demonstrates lexical this, or
  • remove the mention entirely if it's out of scope here?

right now the explanation is correct but loses some educational value.

@bittoby
Copy link
Copy Markdown
Contributor Author

bittoby commented Mar 17, 2026

The fix removes the incorrect claim, which makes the section accurate. however, the original intent seemed to explain lexical this.

Would it be better to either:

  • include a minimal example that actually demonstrates lexical this, or
  • remove the mention entirely if it's out of scope here?

right now the explanation is correct but loses some educational value.

@grayguava Thanks for considering my pr . I see your point. How about adding real example that demonstrates lexical this :

// Example that ACTUALLY uses lexical this
const obj = {
  count: 0,
  start() {
    setInterval(() => {
      this.count++;  // "this" inherited from start() — lexical this!
      console.log(this.count);
    }, 1000);
  },
};

@grayguava
Copy link
Copy Markdown
Contributor

The fix removes the incorrect claim, which makes the section accurate. however, the original intent seemed to explain lexical this.
Would it be better to either:

  • include a minimal example that actually demonstrates lexical this, or
  • remove the mention entirely if it's out of scope here?

right now the explanation is correct but loses some educational value.

@grayguava Thanks for considering my pr . I see your point. How about adding real example that demonstrates lexical this :

// Example that ACTUALLY uses lexical this
const obj = {
  count: 0,
  start() {
    setInterval(() => {
      this.count++;  // "this" inherited from start() — lexical this!
      console.log(this.count);
    }, 1000);
  },
};

This example works well and clearly demonstrates lexical this.
One small suggestion: it might help to briefly contrast it with a function expression to make the difference explicit (since replacing the arrow function would change the behavior).

That could make the explanation clearer for readers who are less familiar with how this works in callbacks.

@Josh-Cena Josh-Cena requested review from Josh-Cena March 17, 2026 10:56
@Josh-Cena
Copy link
Copy Markdown
Member

Thanks, I can't review this at this very moment, but like many MDN pages outside the JS area, anything involving JS mechanics is probably somewhat off😅 I will give the section a read and see if more changes are needed.

@Josh-Cena Josh-Cena removed the request for review from pepelsbey March 17, 2026 10:57
@bittoby
Copy link
Copy Markdown
Contributor Author

bittoby commented Mar 17, 2026

The fix removes the incorrect claim, which makes the section accurate. however, the original intent seemed to explain lexical this.
Would it be better to either:

  • include a minimal example that actually demonstrates lexical this, or
  • remove the mention entirely if it's out of scope here?

right now the explanation is correct but loses some educational value.

@grayguava Thanks for considering my pr . I see your point. How about adding real example that demonstrates lexical this :

// Example that ACTUALLY uses lexical this
const obj = {
  count: 0,
  start() {
    setInterval(() => {
      this.count++;  // "this" inherited from start() — lexical this!
      console.log(this.count);
    }, 1000);
  },
};

This example works well and clearly demonstrates lexical this. One small suggestion: it might help to briefly contrast it with a function expression to make the difference explicit (since replacing the arrow function would change the behavior).

That could make the explanation clearer for readers who are less familiar with how this works in callbacks.

@Josh-Cena Would it be okay if I update my PR based on this feedback?

@Josh-Cena
Copy link
Copy Markdown
Member

Please make any change that you see fit; I will reread the whole thing later.

@github-actions github-actions Bot added size/s [PR only] 6-50 LoC changed and removed size/xs [PR only] 0-5 LoC changed labels Mar 18, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 18, 2026

Preview URLs (2 pages)

(comment last updated: 2026-03-30 19:45:02)

Copy link
Copy Markdown
Member

@pepelsbey pepelsbey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you 🙂

@bittoby
Copy link
Copy Markdown
Contributor Author

bittoby commented Mar 20, 2026

Thanks @pepelsbey would you merge it?

@pepelsbey
Copy link
Copy Markdown
Member

Thanks @pepelsbey would you merge it?

I would wait for @Josh-Cena’s review

@bittoby
Copy link
Copy Markdown
Contributor Author

bittoby commented Mar 24, 2026

@Josh-Cena Please review this PR. It’s been a week since I submitted it, even though it’s simple change.

@Josh-Cena
Copy link
Copy Markdown
Member

Sorry busy week. I'll get to it before EOW. No need to rush

@bittoby
Copy link
Copy Markdown
Contributor Author

bittoby commented Mar 30, 2026

@Josh-Cena Sorry to bother again. I hope you had a great weekend. Please any updates for me.

@github-actions github-actions Bot added size/m [PR only] 51-500 LoC changed and removed size/s [PR only] 6-50 LoC changed labels Mar 30, 2026
Copy link
Copy Markdown
Member

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I've condensed the suggestion into a list and also copied it over to setTimeout. I like the counter example because the array-patching one is itself an antipattern.

@Josh-Cena Josh-Cena merged commit 6ee50f3 into mdn:main Mar 30, 2026
9 checks passed
@bittoby bittoby deleted the fix-setinterval-lexical-this-example branch March 30, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lexical this is mentioned but the associated example doesn't demonstrate it

5 participants