- From: Majid Valipour via GitHub <sysbot+gh@w3.org>
- Date: Wed, 29 Aug 2018 18:18:47 +0000
- To: public-houdini-archive@w3.org
_From @sebmarkbage on September 28, 2016 20:55_ We (React) check for a sentinel on `fn.prototype.isReactComponent` of the function. FWIW, I'm not very happy with this design. Here's the alternative ideas we had and why we didn't choose them: - We could always call `new` and then use duck typing on the return value since ECMAScript lets you return a different object. This doesn't work with non-object return values and unfortunately, you can't call `new` on an arrow function. - We could in theory check for the existence of a `fn.prototype` object at all. This would mean that you could only use arrow functions or methods since they have a `null` prototype. Unfortunately, this doesn't support plain functions nor transpilers that transpile arrow functions. - We could check a static property on the function object itself. `fn.isReactComponent` since in ECMAScript classes static properties are inherited. Unfortunately, many other class systems that are used together with these environments doesn't support them (such as Scala.js). - We could check `instanceof` but that relies on branding that doesn't work with multiple instances of the React libraries, polyfills or realms. - We could change the ECMAScript spec to expose a `Object.isConstructable(fn)` or `Object.isClass(fn)` brand check or similar features. I like this the best but didn't want to go fully down that rabbit hole just yet. -- GitHub Notification of comment by majido Please view or discuss this issue at https://github.com/w3c/css-houdini-drafts/issues/809#issuecomment-417053634 using your GitHub account
Received on Wednesday, 29 August 2018 18:18:56 UTC