Re: [w3c/webcomponents] Non-class based example of customElement.define() (#587)

@rniwa Simply using `Reflect.construct` doesn't solve problems.

`Reflect.construct` is available only in Edge 12+! That's a big (bad) deal because we need to support older systems through polyfills that can't be polyfilled properly, and Custom Elements v1 is relying on not-completely-polyfillable requirements in a day and age when we need it to be 100% polyfillable to make everyone's lives easier.

The strict enforcement of using `new` means that transpilers can not compile to ES5 without using `Reflect.construct` because `Reflect.construct` won't work in anything below Edge 12.

This is a bad because not everyone is off of IE 10 or 11 yet, and there's no way to transpile this to a format that doesn't use `new.target` or `Reflect.construct`.

What this means is that people transpiling this to ES5 and using a Custom Elements v1 and `Reflect` polyfills will get lucky that it works in IE10, but then they'll get the following error in new browsers like Chrome:

```
Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function
```

For example, see how bad this is with [Buble output](https://buble.surge.sh/#class%20FooBar%20extends%20HTMLElement%20%7B%0A%20%20constructor()%20%7B%0A%20%20%20%20super()%0A%20%20%20%20console.log('foo-bar')%0A%20%20%7D%0A%7D%0A%0AcustomElements.define('foo-bar'%2C%20FooBar)%0A%0Anew%20FooBar). Run the output code in Chrome.

This is not good! It makes things very difficult, especially in a time when many people still have to support non-native-ES2015+ environments.

---

Sorry for [posting this twice](https://github.com/w3c/webcomponents/issues/423#issuecomment-333319140), I wanted everyone to see it.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/587#issuecomment-333319571

Received on Saturday, 30 September 2017 16:29:15 UTC