从自定义元素中删除 is="" 属性的预期行为是什么?

What is the expected behavior of removing the is="" attribute from Custom Element?

例如,

假设我们有 <div is="awesomebutton"></div> 和一个自定义元素定义:

document.registerElement('awesomebutton', AwesomeButton)

删除 is="" 属性或用新值替换时的预期行为是什么?

Per section 7 of the latest Working Draft specification (26 February 2016),应该对元素的类型没有影响:

After a custom element is instantiated, changing the value of the is attribute must not affect this element's custom element type.

然而 attributeChangedCallback 仍应正常触发。 (规范并未免除 is 属性触发它。)您可以在支持的浏览器(Chrome 或设置了 dom.webcomponents.enabled 配置标志的 Firefox 中观察到该行为:

'use strict';

const prototype = Object.create(HTMLElement.prototype);
prototype.attributeChangedCallback = function(name, oldValue, newValue) {
  this.textContent = `my "${name}" attribute changed to "${newValue}"!`; 
};

document.registerElement('examp-el', {prototype: prototype, extends: 'div'});

const el = document.createElement('div', 'examp-el');
el.textContent = "I'm an element!";

document.body.appendChild(el);
el.setAttribute('is', "changed once");
el.removeAttribute('is');
el.setAttribute('is', "changed twice");
el.setAttribute('is', "changed thrice");

此规范尚未标准化,即将发生重大变化,但我不希望这种行为发生变化。它仍然由 Section 2.3 of the latest version of the Editor's Draft (currently 17 March 2016):

指定

After a custom element is created, changing the value of the is attribute does not change the element's behavior.