{"action":"created","issue":{"url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4239","repository_url":"https://api.github.com/repos/jashkenas/coffeescript","labels_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4239/labels{/name}","comments_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4239/comments","events_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4239/events","html_url":"https://github.com/jashkenas/coffeescript/issues/4239","id":144809152,"number":4239,"title":"Confusing behaviour when inheriting from classes with bound methods","user":{"login":"jameswilddev","id":3138458,"avatar_url":"https://avatars.githubusercontent.com/u/3138458?v=3","gravatar_id":"","url":"https://api.github.com/users/jameswilddev","html_url":"https://github.com/jameswilddev","followers_url":"https://api.github.com/users/jameswilddev/followers","following_url":"https://api.github.com/users/jameswilddev/following{/other_user}","gists_url":"https://api.github.com/users/jameswilddev/gists{/gist_id}","starred_url":"https://api.github.com/users/jameswilddev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jameswilddev/subscriptions","organizations_url":"https://api.github.com/users/jameswilddev/orgs","repos_url":"https://api.github.com/users/jameswilddev/repos","events_url":"https://api.github.com/users/jameswilddev/events{/privacy}","received_events_url":"https://api.github.com/users/jameswilddev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-03-31T07:03:31Z","updated_at":"2016-03-31T18:54:37Z","closed_at":null,"body":"I understand why this is happening (methods are rebound in the constructor) but this is somewhat confusing; if you inherit from a class and don't call super in the constructor, or call it too late, the bound functions against the class are left unbound, which can be hard to notice as most of the time this has no ill effects, until you try to use one as a callback:\r\n\r\n    class abc\r\n      x: => 4\r\n \r\n    class def extends abc\r\n     constructor: ->\r\n        # Uncomment this to make a.x != b.x\r\n        # super\r\n        return\r\n  \r\n    a = new def()\r\n    b = new def()\r\n\r\n    alert \"#{a.x is b.x}\"\r\n\r\nThis could be fixed by moving the rebindings out of the constructor and into a generated function called automatically before any constructor anywhere down the inheritance tree is called."},"comment":{"url":"https://api.github.com/repos/jashkenas/coffeescript/issues/comments/204076586","html_url":"https://github.com/jashkenas/coffeescript/issues/4239#issuecomment-204076586","issue_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4239","id":204076586,"user":{"login":"vendethiel","id":199499,"avatar_url":"https://avatars.githubusercontent.com/u/199499?v=3","gravatar_id":"","url":"https://api.github.com/users/vendethiel","html_url":"https://github.com/vendethiel","followers_url":"https://api.github.com/users/vendethiel/followers","following_url":"https://api.github.com/users/vendethiel/following{/other_user}","gists_url":"https://api.github.com/users/vendethiel/gists{/gist_id}","starred_url":"https://api.github.com/users/vendethiel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vendethiel/subscriptions","organizations_url":"https://api.github.com/users/vendethiel/orgs","repos_url":"https://api.github.com/users/vendethiel/repos","events_url":"https://api.github.com/users/vendethiel/events{/privacy}","received_events_url":"https://api.github.com/users/vendethiel/received_events","type":"User","site_admin":false},"created_at":"2016-03-31T18:54:37Z","updated_at":"2016-03-31T18:54:37Z","body":"related: #2773"}}