javascript - 带有 ES6 的 webcomponents-lite 在 IE 11 和 10 中不起作用

标签 javascript ecmascript-6 polymer web-component

我们正在使用具有 ES6 语法的 WebComponents。

WebComponents polyfill webcomponents-lite.js(不包括 ShadowDOM)在 IE 11 中不工作,而 webcomponents.js(包括 ShadowDOM)工作正常。对于我们的项目用例,我们希望使用不带 ShadowDOM 的“自定义元素”。

如果我们使用 webcomponents-lite.js,IE 会抛出一个错误 - SCRIPT5022: Exception thrown and not caught.

是否有可用的解决方法?

编辑:我试图在 IE 中使用 webcomponents-lite.js 运行的代码

HTML:<super-button></super-button>

JS(ES6 格式):

class SuperBtn extends HTMLElement {
  constructor() {
      super();
  }
  createdCallback() {
      this.innerHTML = "Invoke Ultron!";
      this.addEventListener('click', () => alert(this.textContent + ' has been clicked'));
    }
}

document.registerElement("super-button", SuperBtn);

最佳答案

是的,您可以使用原始 prototype 表示法声明自定义元素 v1。

这适用于 another polyfill来自 Web 反射:

var CEo = function ()
{
    console.log( "created" )
    return Reflect.construct( HTMLElement, [], CEo )
}

CEo.prototype = Object.create( HTMLElement.prototype )
CEo.prototype.constructor = CEo

CEo.prototype.connectedCallback = function ()
{
    console.log( "connected" )
    this.innerHTML = "Hello v1"
} 

customElements.define( "object-v1", CEo ) 

注意:您需要使用类似 the one of Babel 的 polyfill获取 Reflect.construct 方法。

关于javascript - 带有 ES6 的 webcomponents-lite 在 IE 11 和 10 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39831336/

相关文章:

node.js - Polymer 和 npm,更新到最新版本

javascript - 使用 CSS 样式的颜色代码值字典

javascript - 按对象属性过滤对象数组在 ReactJS 中不起作用

javascript - Node : How to replace certain characters within an array with other characters in javascript

javascript - 如果一个元素包含在另一个元素中,如何检查Javascript

javascript - ES6/ typescript : Stacking map and filter advanced array methods

调试 polymer 纸元素

javascript - 在 JavaScript 中调用对象后的默认字符串值

javascript - 过滤两个对象的值

javascript - 在 Polymer 1.0 中使用选项卡切换 View