internet-explorer - How to use bluebird promises only if browser doesn't support them natively
问题描述
I want to use bluebird
promises to support browsers like IE11 when making http requests using axios
but I'm not using any sort of build tool to bundle my client side dependencies. I'm just importing the bluebird
library from a CDN in my html file. The problem with this is the bluebird promise immediately replaces the native promise on import. Is there any way I can do something similar to this on my client side JS:
if (Promise === undefined)
{
// Use bluebird promise
}
解决方案
这应该可以解决问题,或者至少非常接近:
if (typeof Promise !== "undefined") {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'path to your bluebird file.js'
document.getElementsByTagName('head')[0].appendChild(script);
}
推荐阅读
- python - send_message 不为 pytelegrambotapi 发送消息
- python - 如何将文件作为表单字段输入而不将其定义为 Django 中的模型?
- reactjs - MS Teams 选项卡在部署后不工作但在开发模式下工作
- javascript - 将 HTML 表单下载为 PDF 文件
- javascript - 根据 Bootstrap 中轮播的图像更改显示的文本
- node.js - SockitIO 不断被 cors 政策阻止
- java - 求 List 相同位置的每个列表项的平均值
- >
- roblox - Roblox 数据存储的问题
- extjs - 如何创建图像链接中给出的菜单按钮,在现代工具包 extjs 7.0 中右键单击网格。?
- python - numpy 广播 - 尾轴的解释