有没有实现新的自定义元素规范的环境?

Is there any environment that implements the new custom elements specification?

自定义元素的新版本已在过去的某个时候发布(不确定何时发布,因为我已经有一段时间没有直接使用该规范了)。是否有任何 polyfill 或环境实现了新的自定义元素规范?

我问的原因是我将在周五发表关于 Web 组件规范的演讲,如果没有演示就很难发表演讲,但据我所知,所有浏览器和 polyfill 仍然实现了旧规格查看网络存档,我可以看到新规范已经存在至少几个月了,所以我希望它至少会在某个地方实施。

2020 更新:现在 运行 在 Chrome、Opera 和 Edge (Blink)、Firefox (Gecko) 中,部分在 Safari 中 ( WebKit).

否则你可以使用 WebReflection 的 polyfill for IE11 / Firefox / Chrome.

更改内容的介绍 here


Custom Elements v1 规范自 Chrome v53 起可用。这是本机实现。

注意:您必须运行它带有标志才能激活该功能:

> chrome --enable-blink-features=CustomElementsV1

如果需要,您可以在快捷方式中添加标志。

PS: 我建议使用最后一个版本 (Canary),因为实施会定期更新。


运行 示例:

class CEv1 extends HTMLElement 
{
  constructor () 
  {
    super()
    console.log( "created this=", this )            
  }
  
  connectedCallback ()
  {
    this.innerHTML = "Hello V1!"
  }
} 
customElements.define( "test-v1", CEv1 )
<test-v1>Feature not activated</test-v1>