Giter Site home page Giter Site logo

caveats about custom-elements HOT 5 CLOSED

webcomponents avatar webcomponents commented on July 30, 2024 2
caveats

from custom-elements.

Comments (5)

Shijir avatar Shijir commented on July 30, 2024 1

I am using Typescript. And I had to use the following constructor to make it work.

constructor() {
    return super();
}

from custom-elements.

bicknellr avatar bicknellr commented on July 30, 2024

I'm confused about what the upgrade for procedurally created elements refers to:

The current standard cannot possibly be polifilled "1:1" with vanilla JavaScript because procedurally created instances need an upgrade.

As far as I know, the main problem with CE v1 and polyfills is that you can't actually write a definition that doesn't use ES2015 that also works with a native implementation. Specifically, to construct a native custom element, you must either write it with class syntax and call super(); or use Reflect.construct and pass new.target - both of which are syntax errors in ES5.

Is this demo something like what you were asking about in the original question: http://jsbin.com/tapoqam/1/edit?html,output ?

from custom-elements.

trusktr avatar trusktr commented on July 30, 2024

@bicknellr It means that the instance of your element will go from instanceof HTMLUnknownElement to instanceof YourCustomElement magically, and your reference to it in your code (and in the DOM) will be the same reference. This magic happens on the native (C/C++) side of the engine, not really polyfillable.

from custom-elements.

trusktr avatar trusktr commented on July 30, 2024

@bicknellr Your example works fine because (I believe?) the polyfill just detects and uses the native implementation. But if you add transpiling (es6+ -> es5) then you run into the issues having to ironically use Reflect.construct, etc, even though it isn't es5, because it needs to work when the polyfill detects the native implementation. Transpilation should work fine in a 100% es5 poyfill I think (just guessing, haven't tried yet).

from custom-elements.

dfreedm avatar dfreedm commented on July 30, 2024

README has some caveats for classes with es5 transpilation, this likely should have been closed when that was added.

from custom-elements.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.