{"action":"created","issue":{"url":"https://api.github.com/repos/juliankrispel/decaf/issues/127","repository_url":"https://api.github.com/repos/juliankrispel/decaf","labels_url":"https://api.github.com/repos/juliankrispel/decaf/issues/127/labels{/name}","comments_url":"https://api.github.com/repos/juliankrispel/decaf/issues/127/comments","events_url":"https://api.github.com/repos/juliankrispel/decaf/issues/127/events","html_url":"https://github.com/juliankrispel/decaf/issues/127","id":149986103,"number":127,"title":"coffeescript classes and es6/babel classes aren't compatible","user":{"login":"juliankrispel","id":1188186,"avatar_url":"https://avatars.githubusercontent.com/u/1188186?v=3","gravatar_id":"","url":"https://api.github.com/users/juliankrispel","html_url":"https://github.com/juliankrispel","followers_url":"https://api.github.com/users/juliankrispel/followers","following_url":"https://api.github.com/users/juliankrispel/following{/other_user}","gists_url":"https://api.github.com/users/juliankrispel/gists{/gist_id}","starred_url":"https://api.github.com/users/juliankrispel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliankrispel/subscriptions","organizations_url":"https://api.github.com/users/juliankrispel/orgs","repos_url":"https://api.github.com/users/juliankrispel/repos","events_url":"https://api.github.com/users/juliankrispel/events{/privacy}","received_events_url":"https://api.github.com/users/juliankrispel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-21T07:07:59Z","updated_at":"2016-05-04T03:30:05Z","closed_at":null,"body":"cc @eventualbuddha \r\n\r\nRight. So at rainforest we have a legacy coffeescript/backbone codebase (which I'm trying to rid ourselves of). I've observed two problems that are a major PITA, in regards to classes.\r\n\r\n## Problem 1: Es6 inheritance doesn't include static members but CS inheritance does\r\n\r\nGiven the example\r\n\r\n```coffeescript\r\nclass A\r\n\r\nA.b = [1,2,3]\r\n\r\nclass B extends A\r\n\r\nconsole.log(B.b) // yields [1,2,3]\r\n```\r\nThe above works in coffeescript because of the `extend` helper function in coffeescript. It copies the prototype as well as any `static` members of the class.\r\n\r\nHowever in es6, class inheritance doesn't include static members. This means only the prototype is copied.\r\n\r\n## Problem 2: In Coffeescript, static class properties are mounted before the constructor is called, in es6 it's the other way around.\r\n\r\nGiven the example\r\n```js\r\nfunction A(){\r\n  console.log(this.routes); // yields undefined\r\n}\r\n\r\nclass B extends A {\r\n  routes = ['dwq', 'dwq']\r\n}\r\n\r\nnew B({routes: [1,2,3]});\r\n```\r\nthe static attribute routes will actually not be mounted when constructor `A()` is executed.\r\n\r\n@eventualbuddha any ideas how to solve these two? Or maybe you've already addressed these?\r\n"},"comment":{"url":"https://api.github.com/repos/juliankrispel/decaf/issues/comments/216733294","html_url":"https://github.com/juliankrispel/decaf/issues/127#issuecomment-216733294","issue_url":"https://api.github.com/repos/juliankrispel/decaf/issues/127","id":216733294,"user":{"login":"eventualbuddha","id":1938,"avatar_url":"https://avatars.githubusercontent.com/u/1938?v=3","gravatar_id":"","url":"https://api.github.com/users/eventualbuddha","html_url":"https://github.com/eventualbuddha","followers_url":"https://api.github.com/users/eventualbuddha/followers","following_url":"https://api.github.com/users/eventualbuddha/following{/other_user}","gists_url":"https://api.github.com/users/eventualbuddha/gists{/gist_id}","starred_url":"https://api.github.com/users/eventualbuddha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eventualbuddha/subscriptions","organizations_url":"https://api.github.com/users/eventualbuddha/orgs","repos_url":"https://api.github.com/users/eventualbuddha/repos","events_url":"https://api.github.com/users/eventualbuddha/events{/privacy}","received_events_url":"https://api.github.com/users/eventualbuddha/received_events","type":"User","site_admin":false},"created_at":"2016-05-04T03:30:05Z","updated_at":"2016-05-04T03:30:05Z","body":"For problem 1, I don't think that's actually an issue. [This example](https://babeljs.io/repl/#?evaluate=true&lineWrap=false&presets=es2015%2Creact%2Cstage-1%2Cstage-2&code=class%20A%20%7B%0A%20%20static%20b%20%3D%20%5B1%2C%202%2C%203%5D%0A%7D%0A%0Aclass%20B%20extends%20A%20%7B%7D%0A%0Aconsole.log(B.b)%3B) works the same way as the CoffeeScript one:\r\n\r\n```js\r\nclass A {\r\n  static b = [1, 2, 3]\r\n}\r\n\r\nclass B extends A {}\r\n\r\nconsole.log(B.b);\r\n```\r\n\r\nFor problem 2, the `routes = …` part becomes something like this in a constructor: `this.routes = …`, but that has to happen after the implicit `super()` call. So it works in CoffeeScript because the `routes = …` becomes part of the prototype rather than a constructor assignment. I haven't done anything to address this 😞 I tend to favor the idiomatic approach over the exactly compatible one. ¯\\_(ツ)_/¯\r\n"}}