Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28478

Re: Class with internal callback referencing itself.

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 <ben.usenet@bsb.me.uk>
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> (permalink)
References <f7ab5abb-4bbc-4e22-9b5d-dc347d500f82@googlegroups.com>
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

Show key headers only | View raw


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.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Class with internal callback referencing itself. puritanpaul@gmail.com - 2015-07-29 00:50 -0700
  Re: Class with internal callback referencing itself. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-07-29 10:13 +0200
  Re: Class with internal callback referencing itself. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-29 10:49 +0100
    Re: Class with internal callback referencing itself. Jonathan Price <puritanpaul@gmail.com> - 2015-07-29 11:48 -0700

csiph-web