IE11 函数未通过构造函数
IE11 function not getting passed constructor
在页面加载时,我正在触发一个应该打开灯箱的功能。在 Chrome、FF、Opera、Edge 和 Safari 中,一切正常。然而在 IE11 中它不是。我没有在控制台中收到警告或错误,所以我不知道我在这里做错了什么。
我将下面的代码精简到最基本的部分。在 Chrome(和其他浏览器)中,控制台日志从 1 变为 3 再变为 2。在 IE11 中,我只得到 1,我不知道为什么它没有变为 3 或 2。我认为它有一些东西与 bind() 有关,但这似乎得到支持。
我不得不承认我对构造函数、原型和绑定还很陌生。
constructor(el) {
this.$el = $(el);
console.log('1');
this.getLocation = getLocation.bind(this);
this.loadLB();
console.log('2');
}
loadLB() {
const url = new URL(window.location.href);
console.log('3');
this.getLocation('url');
}
您在使用 ConstructorMethod 吗? IE也不支持它。不知道你有没有用过一些polyfill让它在IE 11中正常工作
另外,IE不支持URL() constructor。您可以添加此 polyfill 以使 URL()
在 IE 11 中工作:
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
在页面加载时,我正在触发一个应该打开灯箱的功能。在 Chrome、FF、Opera、Edge 和 Safari 中,一切正常。然而在 IE11 中它不是。我没有在控制台中收到警告或错误,所以我不知道我在这里做错了什么。
我将下面的代码精简到最基本的部分。在 Chrome(和其他浏览器)中,控制台日志从 1 变为 3 再变为 2。在 IE11 中,我只得到 1,我不知道为什么它没有变为 3 或 2。我认为它有一些东西与 bind() 有关,但这似乎得到支持。
我不得不承认我对构造函数、原型和绑定还很陌生。
constructor(el) {
this.$el = $(el);
console.log('1');
this.getLocation = getLocation.bind(this);
this.loadLB();
console.log('2');
}
loadLB() {
const url = new URL(window.location.href);
console.log('3');
this.getLocation('url');
}
您在使用 ConstructorMethod 吗? IE也不支持它。不知道你有没有用过一些polyfill让它在IE 11中正常工作
另外,IE不支持URL() constructor。您可以添加此 polyfill 以使 URL()
在 IE 11 中工作:
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>