-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
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
Update tooltip.js #19541
Update tooltip.js #19541
Conversation
Don't reference `Tether` via attachment to `window`, with the update one can import bootstrap providing the dependencies in webpack with: ``` new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', Tether: 'tether', }); ``` Then inside one's own bootstrap/globals, `import 'bootstrap';` will simply work, and $/jQuery can be used from there. I had wanted to do this, but also expose jQuery, Tether, etc when in development build in my code, but if I provide `window.Tether`, I can't then expose it to the outside...
match project's style check
@@ -16,7 +16,7 @@ const Tooltip = (($) => { | |||
* Check for Tether dependency | |||
* Tether - http://github.hubspot.com/tether/ | |||
*/ | |||
if (window.Tether === undefined) { | |||
if (typeof Tether === 'undefined') { |
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.
Why not just : if (Tether === undefined)
?
Your JSPerf prove it's faster than using typeof
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.
@Johann-S That will throw an exception if Tether isn't defined...
if (someUndefinedValue === undefined) console.log('success')
// Uncaught ReferenceError someUndefinedValue is not defined
//this would work, but sloppier than the typeof
try {
if (Tether){}
} catch(err) {
throw new Error('Bootstrap tooltips require Tether (http://github.hubspot.com/tether/');
}
@vsn4ik in your example
You will see...
Since Not to mention that the test in this case is really contrived, as it is only run a single time when the file in question is loaded, not millions of iterations. |
@bardiharborow @Johann-S Do we need this? I'm unclear if this helps us at all. |
I can't see any reason why we shouldn't merge this and close #20745. The issue here is that we want our code to work when Tether is loaded at both |
Don't reference
Tether
via attachment towindow
, with the update one can import bootstrap providing the dependencies in webpack with:Then inside one's own bootstrap/globals,
import 'bootstrap';
will simply work, and $/jQuery can be used from there.I had wanted to do this, but also expose jQuery, Tether, etc when in development build in my code, but if I provide
window.Tether
, I can't then expose it to the outside...