How to extend an existing custom element?

放肆的年华 提交于 2019-12-12 16:16:21

问题


I have a custom element, called x-foo. I would like to extend it, and create an x-foo-extended element, but it doesn't works. I get this error:

Uncaught NotSupportedError: Failed to execute 'registerElement' on 'Document': Registration failed for type 'x-foo-extended'. The tag name specified in 'extends' is a custom element name. Use inheritance instead.

    var xFooExtendedProto = Object.create(xFoo.prototype);

    xFooExtendedProto.someCustomFunc = function() {
        // ...
    };

    xFooExtended = document.registerElement('x-foo-extended', {
        prototype: xFooExtendedProto,
        extends: 'x-foo'
    });

回答1:


According to the spec , this is not permitted. From the spec: "If BASE does not exist or is an interface for a custom element, set ERROR to InvalidName and stop."

Source: As described by the person who implemented custom elements in Chrome https://lists.w3.org/Archives/Public/public-webapps/2014OctDec/0155.html



来源:https://stackoverflow.com/questions/27769119/how-to-extend-an-existing-custom-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!