Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: Class with internal callback referencing itself. Date: Wed, 29 Jul 2015 10:49:45 +0100 Organization: A noiseless patient Spider Lines: 28 Message-ID: <87mvyf5m4m.fsf@bsb.me.uk> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="8115"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+a3eniHBPXpH+GGtAF1KcGmD39iMgjpos=" Cancel-Lock: sha1:7ZF08pVRsiGAyNpzi+BLJOWGlJU= sha1:N0a7X2Mcmy1g0r3mTxUsQb3lDNk= X-BSB-Auth: 1.df83f2832bee404a914e.20150729104945BST.87mvyf5m4m.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:28478 puritanpaul@gmail.com writes: > Can someone offer a way around this problem? > > MyClass.prototype.selectClinic = function() { > this.otherClass.doSomething( this.selectClinicSuccess ); > } > > MyClass.prototype.selectClinicSuccess = function() { > this.getProperty() > } > > MyClass.prototype.getProperty = function() { > // do some stuff > } > > When I land in selectClinicSuccess, I'm getting this.getProperty is > not a function. You don't show enough code to be sure, but passing this.selectClinicSuccess to doSomething is almost certainly wrong. doSomething probably call calls its argument, in which case 'this' will be undefined inside selectClinicSuccess. You might want this.otherClass.doSomething( this.selectClinicSuccess.bind(this) ); -- Ben.