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


Groups > comp.lang.javascript > #28478

Re: Class with internal callback referencing itself.

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.javascript
Subject Re: Class with internal callback referencing itself.
Date 2015-07-29 10:49 +0100
Organization A noiseless patient Spider
Message-ID <87mvyf5m4m.fsf@bsb.me.uk> (permalink)
References <f7ab5abb-4bbc-4e22-9b5d-dc347d500f82@googlegroups.com>

Show all headers | 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