{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/react/issues/4509","labels_url":"https://api.github.com/repos/facebook/react/issues/4509/labels{/name}","comments_url":"https://api.github.com/repos/facebook/react/issues/4509/comments","events_url":"https://api.github.com/repos/facebook/react/issues/4509/events","html_url":"https://github.com/facebook/react/issues/4509","id":97673485,"number":4509,"title":"ES6 class methods not binded to class instances","user":{"login":"jpinho","id":4655079,"avatar_url":"https://avatars.githubusercontent.com/u/4655079?v=3","gravatar_id":"","url":"https://api.github.com/users/jpinho","html_url":"https://github.com/jpinho","followers_url":"https://api.github.com/users/jpinho/followers","following_url":"https://api.github.com/users/jpinho/following{/other_user}","gists_url":"https://api.github.com/users/jpinho/gists{/gist_id}","starred_url":"https://api.github.com/users/jpinho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpinho/subscriptions","organizations_url":"https://api.github.com/users/jpinho/orgs","repos_url":"https://api.github.com/users/jpinho/repos","events_url":"https://api.github.com/users/jpinho/events{/privacy}","received_events_url":"https://api.github.com/users/jpinho/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-28T10:42:22Z","updated_at":"2015-07-28T10:56:35Z","closed_at":null,"body":"Let's say we have a class like this:\r\n\r\n    export default class BasePlayer extends React.Component {\r\n          myMethod(){ }\r\n    }\r\n\r\nThen, if I use this BasePlayer inside another component and I name it with \"ref=basePlayer\", like this:\r\n\r\n    class SomeComponent extends React.Component {\r\n        ...\r\n       render(){\r\n            return <div><BasePlayer ref=\"basePlayer\" /></div>\r\n        }\r\n        ...\r\n    }\r\n\r\nThe problem is that, from the class SomeComponent I can't call \"this.refs.basePlayer.myMethod()\", because the methods are not binded to the basePlayer instance.\r\n\r\nTo fixed it what I did was, to manually bind/expose my methods from the BasePlayer constructor like this:\r\n\r\n    constructor(props){\r\n        super(props);\r\n\r\n        /*public methods*/ \r\n        this.myMethod= this.myMethod;\r\n    }\r\n\r\nBut it should be automatic... Is there a better way to achieve this?"},"comment":{"url":"https://api.github.com/repos/facebook/react/issues/comments/125556137","html_url":"https://github.com/facebook/react/issues/4509#issuecomment-125556137","issue_url":"https://api.github.com/repos/facebook/react/issues/4509","id":125556137,"user":{"login":"syranide","id":1714255,"avatar_url":"https://avatars.githubusercontent.com/u/1714255?v=3","gravatar_id":"","url":"https://api.github.com/users/syranide","html_url":"https://github.com/syranide","followers_url":"https://api.github.com/users/syranide/followers","following_url":"https://api.github.com/users/syranide/following{/other_user}","gists_url":"https://api.github.com/users/syranide/gists{/gist_id}","starred_url":"https://api.github.com/users/syranide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/syranide/subscriptions","organizations_url":"https://api.github.com/users/syranide/orgs","repos_url":"https://api.github.com/users/syranide/repos","events_url":"https://api.github.com/users/syranide/events{/privacy}","received_events_url":"https://api.github.com/users/syranide/received_events","type":"User","site_admin":false},"created_at":"2015-07-28T10:56:35Z","updated_at":"2015-07-28T10:56:35Z","body":"> The problem is that, from the class SomeComponent I can't call \"this.refs.basePlayer.myMethod()\", because the methods are not binded to the basePlayer instance.\r\n\r\nThat sould work just fine, when called as `basePlayer.myMethod()` as you show.\r\n\r\nIf `this.myMethod = this.myMethod;` solves it then I assume there's something wrong with how your classes are set up/handled."}}