【发布时间】:2020-10-30 11:10:41
【问题描述】:
是否可以修改customElements.define 并改用自定义函数?
这是我迄今为止尝试过的,但显然这不起作用,因为window.customElements 是只读的。
const future = ["hello-world"];
let customElementsRegistry = window.customElements;
const registry = {};
registry.define = function(name, constructor, options) {
if (future.includes(name)) {
customElementsRegistry.define(name, constructor, options);
}
}
window.customElements = registry;
window.customElements.define("hello-world", HelloWorld);
这是可能的还是我唯一的选择来创建我自己的registry 并使用那个?
【问题讨论】:
标签: javascript web-component custom-element