{"action":"created","issue":{"url":"https://api.github.com/repos/ReactiveX/RxJS/issues/1366","repository_url":"https://api.github.com/repos/ReactiveX/RxJS","labels_url":"https://api.github.com/repos/ReactiveX/RxJS/issues/1366/labels{/name}","comments_url":"https://api.github.com/repos/ReactiveX/RxJS/issues/1366/comments","events_url":"https://api.github.com/repos/ReactiveX/RxJS/issues/1366/events","html_url":"https://github.com/ReactiveX/RxJS/issues/1366","id":134863153,"number":1366,"title":"This reference is lost in catch handler of an Observable","user":{"login":"CaselIT","id":16175304,"avatar_url":"https://avatars.githubusercontent.com/u/16175304?v=3","gravatar_id":"","url":"https://api.github.com/users/CaselIT","html_url":"https://github.com/CaselIT","followers_url":"https://api.github.com/users/CaselIT/followers","following_url":"https://api.github.com/users/CaselIT/following{/other_user}","gists_url":"https://api.github.com/users/CaselIT/gists{/gist_id}","starred_url":"https://api.github.com/users/CaselIT/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CaselIT/subscriptions","organizations_url":"https://api.github.com/users/CaselIT/orgs","repos_url":"https://api.github.com/users/CaselIT/repos","events_url":"https://api.github.com/users/CaselIT/events{/privacy}","received_events_url":"https://api.github.com/users/CaselIT/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-02-19T13:21:29Z","updated_at":"2016-02-19T18:48:38Z","closed_at":"2016-02-19T18:13:50Z","body":"I'm not sure if this is a bug of RxJS or not.\r\nTaking as an example the code below with creates an observer and handles its exception in a method of the class.\r\n```ts\r\nimport { Observable } from 'rxjs';\r\nclass ObservableTest {\r\n  methodReference() {\r\n    return new Observable((obs) => obs.error('Method reference')).catch(this.handler);\r\n  }\r\n  fatArrow() {\r\n    return new Observable((obs) => obs.error('Fat Arrow')\r\n    ).catch((err, src, c) => this.handler(err, src, c));\r\n  }\r\n  handler(err, src, c) {\r\n    console.log(`${err}: `, this === observableTest);\r\n    return Observable.empty();\r\n  }\r\n}\r\nvar observableTest = new ObservableTest()\r\nobservableTest.methodReference().subscribe();\r\nobservableTest.fatArrow().subscribe();\r\n```\r\nIn `methodReference()` in the catch function call I use the method reference, while in `fatArrow()` I use the fat arrow syntax to invoke the handler.\r\nThe problem I have is that I lose the reference to the class instance in the `this` variable when using the method reference.\r\nFor instance the above code prints\r\n```\r\nMethod reference:  false\r\nFat Arrow:  true\r\n```\r\nAgain I'm not sure if the problem is of RxJS. I'm using typescript and RxJS 5.0.0-beta.2, but the above code should be valid es6."},"comment":{"url":"https://api.github.com/repos/ReactiveX/RxJS/issues/comments/186357872","html_url":"https://github.com/ReactiveX/RxJS/issues/1366#issuecomment-186357872","issue_url":"https://api.github.com/repos/ReactiveX/RxJS/issues/1366","id":186357872,"user":{"login":"david-driscoll","id":1269157,"avatar_url":"https://avatars.githubusercontent.com/u/1269157?v=3","gravatar_id":"","url":"https://api.github.com/users/david-driscoll","html_url":"https://github.com/david-driscoll","followers_url":"https://api.github.com/users/david-driscoll/followers","following_url":"https://api.github.com/users/david-driscoll/following{/other_user}","gists_url":"https://api.github.com/users/david-driscoll/gists{/gist_id}","starred_url":"https://api.github.com/users/david-driscoll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/david-driscoll/subscriptions","organizations_url":"https://api.github.com/users/david-driscoll/orgs","repos_url":"https://api.github.com/users/david-driscoll/repos","events_url":"https://api.github.com/users/david-driscoll/events{/privacy}","received_events_url":"https://api.github.com/users/david-driscoll/received_events","type":"User","site_admin":false},"created_at":"2016-02-19T18:48:38Z","updated_at":"2016-02-19T18:48:38Z","body":"That is correct, that is the \"intended\" behavior for JavaScript.  No matter how confusing it might be when you compare the behavior in other languages, such as C# where that's my main background."}}