根据
current proposal docs
,您想添加一个
extras
finish
方法,该方法将在类完全定义后作为参数与类本身一起调用。
下面是示例代码:
function defineElement(tagName) {
return function(classDescriptor) {
let { kind, elements } = classDescriptor;
assert(kind == "class");
return {
kind,
elements,
// This callback is called once the class is otherwise fully defined
extras: [
{
kind: "hook",
placement: "static",
finish(klass) {
window.customElements.define(tagName, klass);
}
}
]
};
};
额外费用
extras: [
{
kind: "hook",
placement: "static",
finish(klass) {
type_registry[tag] = klass;
},
},
],