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


Groups > comp.lang.javascript > #28476 > unrolled thread

Class with internal callback referencing itself.

Started bypuritanpaul@gmail.com
First post2015-07-29 00:50 -0700
Last post2015-07-29 11:48 -0700
Articles 4 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  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

#28476 — Class with internal callback referencing itself.

Frompuritanpaul@gmail.com
Date2015-07-29 00:50 -0700
SubjectClass with internal callback referencing itself.
Message-ID<f7ab5abb-4bbc-4e22-9b5d-dc347d500f82@googlegroups.com>
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.

Thanks

[toc] | [next] | [standalone]


#28477

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-07-29 10:13 +0200
Message-ID<XnsA4E668077FF6Aeejj99@194.109.6.166>
In reply to#28476
puritanpaul@gmail.com wrote on 29 Jul 2015 in comp.lang.javascript:

> 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. 

Could it be you are making an unapproved landing 
on a Javascript runway not designed for getProperty()?

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#28478

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2015-07-29 10:49 +0100
Message-ID<87mvyf5m4m.fsf@bsb.me.uk>
In reply to#28476
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.

[toc] | [prev] | [next] | [standalone]


#28479

FromJonathan Price <puritanpaul@gmail.com>
Date2015-07-29 11:48 -0700
Message-ID<a53bbc51-c980-4df8-8731-a84e907173a8@googlegroups.com>
In reply to#28478
Perfect!  I didn't know about function binding, but it makes a lot of sense.  Thanks for the help.


> 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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web