-
-
Notifications
You must be signed in to change notification settings - Fork 78.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix this reference for functions #38725
base: main
Are you sure you want to change the base?
Conversation
/CC @GeoSot |
@@ -143,7 +143,7 @@ class TemplateFactory extends Config { | |||
} | |||
|
|||
_resolvePossibleFunction(arg) { | |||
return execute(arg, [this]) | |||
return execute(arg, [undefined, this]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return execute(arg, [undefined, this]) | |
return typeof arg === 'function' ? arg.call(this._element) : arg |
I suppose it is better to change only this, as it is count as a regression, and add a test, instead of messing all the rest calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This callsite doesn't actually matter, AFAICT. There are two calls where the this
argument is important:
_resolvePossibleFunction
injs/src/tooltip.js
- The call to
execute(this._config.placement, ...)
in_createPopper
injs/src/tooltip.js
I can update those two call sites to use the typeof arg === 'function' ...
pattern if you'd prefer that I avoid changing execute
?
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
ec77195
to
9148528
Compare
Seems good to go @GeoSot? |
Description
This PR fixes the bug described in #38720. Functions like
content
andtitle
weren't being called with the correctthis
reference.Motivation & Context
As far as I can tell, #36652 introduced this regression. It switched from calling the function with a specific
this
value to calling it with that value as the first argument.While this appears to have been unintentional, folks may have started relying on that first argument as a workaround, and thus it could be considered part of the API. I didn't do anything about that yet, but it might be reasonable to retain both the old and new behavior (that is, for functions like
content
, call it with both a specificthis
value and an explicit argument). I can make that change and update the documentation if requested.I repurposed the existing
execute()
function to support this. If a second argument is provided, it will be an array, and the first value will be treated as thethis
argument. This is done by just passing the entire arguments array tocall
. This required addingundefined
as the first value in some places that don't expect an specificthis
value.Type of changes
Checklist
npm run lint
)Related issues
Fixes #38720.