Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28476 > unrolled thread
| Started by | puritanpaul@gmail.com |
|---|---|
| First post | 2015-07-29 00:50 -0700 |
| Last post | 2015-07-29 11:48 -0700 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.lang.javascript
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
| From | puritanpaul@gmail.com |
|---|---|
| Date | 2015-07-29 00:50 -0700 |
| Subject | Class 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]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-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]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-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]
| From | Jonathan Price <puritanpaul@gmail.com> |
|---|---|
| Date | 2015-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