Rick Waldron (2013-12-28T23:21:39.000Z)
domenic at domenicdenicola.com (2014-01-08T19:53:32.557Z)
On Sat, Dec 28, 2013 at 8:35 AM, Sebastian Markbåge <sebastian at calyptus.eu> wrote: > I completely agree that is the intended use and what we should be > encouraging people to do. What I'm asking for is to intentionally break > best-practices for a specialized use case. > > The use case I had in mind was React components. Components in React are > described as classes which makes them seem approachable to a broad user > base. They cannot and should not be accessed as class instances though. The > instances are immutable data structures used exclusively by the library. > The base constructor could look something like this: > > ```js > constructor(x) { > return { _hiddenInstance: this, _instantiationContext: CurrentContext, > _id: uid(), _someArgument: x }; > } > ``` > > This would generate a descriptor that can be used by the library but only > used as a reference by the user. This allows users to declare classes just > like they're used to and even instantiate them normally. However, they'd > only be given access to the real instance at the discretion of the library. We're doing this with Maps (for non-DOM bound data) and WeakMaps (for DOM bound data) in the FirefoxOS Messages app (for Recipients, Threads and Draft data objects).