Skip to content

Comments

Array.groupByXxxx - clarify thisArg#14421

Merged
sideshowbarker merged 1 commit intomdn:mainfrom
hamishwillee:array_group_this
Mar 29, 2022
Merged

Array.groupByXxxx - clarify thisArg#14421
sideshowbarker merged 1 commit intomdn:mainfrom
hamishwillee:array_group_this

Conversation

@hamishwillee
Copy link
Collaborator

Array.groupBy() and Array.groupByToMap() take a thisArg parameter.

The docs followed the spec, which stated that the function is called with undefined if the argument is not specified. The engineering team clarified that this is is not the full story - functions are always called with a this argument, and the handling depends on the function and scope.

Upshot is that if thisArg will actually only be undefined in a normal function called in strict mode. Otherwise it will take the scope appropriate for the function type - i.e. in an arrow function the lexical scope. In a normal function the calling scope.

This follows on from discussion here: https://github.com/mdn/content/pull/13171/files#r816339510

@hamishwillee hamishwillee requested a review from a team as a code owner March 29, 2022 03:40
@hamishwillee hamishwillee requested review from wbamberg and removed request for a team March 29, 2022 03:40
@github-actions github-actions bot added the Content:JS JavaScript docs label Mar 29, 2022
@sideshowbarker sideshowbarker merged commit 23903ac into mdn:main Mar 29, 2022
Copy link

@Matt5j Matt5j left a comment

Choose a reason for hiding this comment

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

@hamishwillee hamishwillee deleted the array_group_this branch March 31, 2022 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:JS JavaScript docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants