{"action":"created","issue":{"url":"https://api.github.com/repos/dojo/compose/issues/5","labels_url":"https://api.github.com/repos/dojo/compose/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/dojo/compose/issues/5/comments","events_url":"https://api.github.com/repos/dojo/compose/issues/5/events","html_url":"https://github.com/dojo/compose/issues/5","id":111124172,"number":5,"title":"Using ES6 and TypeScript classes as a base","user":{"login":"kitsonk","id":1282577,"avatar_url":"https://avatars.githubusercontent.com/u/1282577?v=3","gravatar_id":"","url":"https://api.github.com/users/kitsonk","html_url":"https://github.com/kitsonk","followers_url":"https://api.github.com/users/kitsonk/followers","following_url":"https://api.github.com/users/kitsonk/following{/other_user}","gists_url":"https://api.github.com/users/kitsonk/gists{/gist_id}","starred_url":"https://api.github.com/users/kitsonk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kitsonk/subscriptions","organizations_url":"https://api.github.com/users/kitsonk/orgs","repos_url":"https://api.github.com/users/kitsonk/repos","events_url":"https://api.github.com/users/kitsonk/events{/privacy}","received_events_url":"https://api.github.com/users/kitsonk/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dojo/compose/labels/discussion","name":"discussion","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-10-13T07:48:39Z","updated_at":"2015-11-19T11:44:48Z","closed_at":null,"body":"Currently the `create` and `mixin` API can accept ES6 and TypeScript classes.  There are a few \"challenges\" with using these, it can especially get confusing with the type inference.\r\n\r\nAt the moment, none of the constructor functions are executed.  This was mainly to avoid any unintended consequences of the constructors.  In addition, you cannot directly call ES6 constructors without the `new` keyword, meaning that several instances would be created and thrown away during construction.\r\n\r\nFrom a disadvantage point, you do not get any of the affects of the constructor.  This is very important though when using non-method properties in TypeScript classes as the type inferrance will abstract those properties from the class, but since then TypeScript moves all of that property setting to the constructor on emit, you don't actually get the values defined.  For example, this does not work properly with compose:\r\n\r\n```typescript\r\nimport compose from 'dojo-compose/compose';\r\n\r\nclass Foo {\r\n  foo: string = 'bar';\r\n}\r\n\r\nconst ComposeFoo = compose(Foo);\r\nconst foo = new ComposeFoo();\r\nconsole.log(foo.bar); // outputs `undefined`\r\n```\r\n\r\nI see two paths forward:\r\n - Explain this behaviour and why.\r\n - Change the behaviour, using some sort of intelligence in create which would under ES5 pass the instance to the constructors in the class and in ES6 create new instances for each constructor and then mix in anything that wasn't in the prototype.\r\n"},"comment":{"url":"https://api.github.com/repos/dojo/compose/issues/comments/158032459","html_url":"https://github.com/dojo/compose/issues/5#issuecomment-158032459","issue_url":"https://api.github.com/repos/dojo/compose/issues/5","id":158032459,"user":{"login":"kitsonk","id":1282577,"avatar_url":"https://avatars.githubusercontent.com/u/1282577?v=3","gravatar_id":"","url":"https://api.github.com/users/kitsonk","html_url":"https://github.com/kitsonk","followers_url":"https://api.github.com/users/kitsonk/followers","following_url":"https://api.github.com/users/kitsonk/following{/other_user}","gists_url":"https://api.github.com/users/kitsonk/gists{/gist_id}","starred_url":"https://api.github.com/users/kitsonk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kitsonk/subscriptions","organizations_url":"https://api.github.com/users/kitsonk/orgs","repos_url":"https://api.github.com/users/kitsonk/repos","events_url":"https://api.github.com/users/kitsonk/events{/privacy}","received_events_url":"https://api.github.com/users/kitsonk/received_events","type":"User","site_admin":false},"created_at":"2015-11-19T11:44:48Z","updated_at":"2015-11-19T11:44:48Z","body":"@mwistrand that is the challenge that I have, there could likely be side-effects, which would have to be worked through, but essentially what I was thinking was something that during the mixin process, that an instance of the class would be created, the own properties would be mixed into the prototype and then own properties of the `instance.prototype` would be mixed in.\r\n\r\nSome considerations are that in ES7, [class properties](https://github.com/jeffmo/es-class-fields-and-static-properties) are being proposed.\r\n\r\nI agree the intent is the class compatibility as a by product, but in certain ways, we should try to may the byproduct as easy (and unsurprising) as possible.\r\n\r\nOne other thought, it is theoretically possible to utilise the Reflect API to detect any class properties that are being passed in and then \"throw\" (or possibly define them), but that would add runtime overhead to the composition process."}}