Imp.wakeup() context issue

Using the IDE

`

class PingPong
{
constructor() {
}

function pong()
{
    server.log("pong");
}
function pongCB()
{
    pong();        // <-- the callback can't find pong() in the callback context?
}
function ping() {
    server.log("ping");
    imp.wakeup(1.0, this.pongCB);
}

}

pingpong <- PingPong();
pingpong.ping();
`

ERROR: the index ‘pong’ does not exist

However if I make wakeup() call a “global” callback such as:

`
function globalPong() {
pingpong.pongCB();
}
class PingPong
{
constructor() {
}

function pong()
{
    server.log("pong");
}
function pongCB()
{
    pong();        
}
function ping() {
    server.log("ping");
    imp.wakeup(1.0, globalPong);
}

}

pingpong <- PingPong();
pingpong.ping();
`

This works without issue. Is it invalid to give wakeup a callback to a class method?

You need to use bindenv, eg:

imp.wakeup(1.0, pongCB.bindenv(this));

See here, for another example http://devwiki.electricimp.com/doku.php?id=examplerfid&s[]=bindenv

@Hugo - Thanks a bunch!