Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #32416
| From | Martin Honnen <martin.honnen@gmx.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: ES6 class properties are undefined ? |
| Date | 2017-01-29 12:55 +0100 |
| Organization | Liberty Development |
| Message-ID | <o6kl8c$cro$1@news.albasani.net> (permalink) |
| References | <o6kc0n$jep$1@shakotay.alphanet.ch> <o6ki2m$ek5$1@news.albasani.net> <o6kiqf$vbn$1@shakotay.alphanet.ch> |
On 29.01.2017 12:14, Une Bévue wrote:
> Le 29/01/2017 à 12:01, Martin Honnen a écrit :
>> Try whether using
>> that.timerID = window.setInterval(function() { that.init(); }, 5000);
>
> Fine, thanks, that works !
>
> Do you have an explanation ?
Your attempt with
that.timerID = window.setInterval(that.init, 5000);
passes the function reference the expression `that.init` gives to
setInterval, it is then executed later in the context of the window
object and not of the SocketService instance you want it to be called
on. My suggestion passes a function reference forming a closure on the
`that` variable and that way setInterval calls the method on the
intended instance and not on the window object.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
ES6 class properties are undefined ? Une Bévue <unbewusst.sein@fai.invalid> - 2017-01-29 10:18 +0100
Re: ES6 class properties are undefined ? Martin Honnen <martin.honnen@gmx.de> - 2017-01-29 12:01 +0100
Re: ES6 class properties are undefined ? Une Bévue <unbewusst.sein@fai.invalid> - 2017-01-29 12:14 +0100
Re: ES6 class properties are undefined ? Martin Honnen <martin.honnen@gmx.de> - 2017-01-29 12:55 +0100
Re: ES6 class properties are undefined ? Une Bévue <unbewusst.sein@fai.invalid> - 2017-01-29 15:50 +0100
Re: ES6 class properties are undefined ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-01-29 14:00 +0100
Re: ES6 class properties are undefined ? Une Bévue <unbewusst.sein@fai.invalid> - 2017-01-29 15:56 +0100
csiph-web