Skip to content

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

Open
bittoby wants to merge 2 commits intomdn:mainfrom
bittoby:fix-setinterval-lexical-this-example
Open

fix: Fix misleading lexical claim in setInterval docs to match the actual example#43465
bittoby wants to merge 2 commits intomdn:mainfrom
bittoby:fix-setinterval-lexical-this-example

Conversation

@bittoby
Copy link
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
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
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
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
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
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
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
Contributor

Preview URLs (1 page)

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/s [PR only] 6-50 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

4 participants