Can`t call console.log() from event listener

907 views Asked by At

I'm performing an app for tizen, but it has a lot of pure JS code and I faced with strange problem. I have such listener of event:

messagesChangeListener: function () {
    var self = this, config,
messageChangeCallback = {
    messagesupdated: function (updateMessages) {
        //console.log('Message updated');
    },
    messagesadded: function (addedMessage) {
        //console.log('Message added: ');
        self.outputlog(addedMessage);
    },
    messagesremoved: function (removedMessages) {
        //console.log('Message removed');
    }
};  this.smsService.messageStorage.addMessagesChangeListener(messageChangeCallback);
    },

outputlog: function(messages) {
    console.log("Messages changed");
},

As you see I have event handlers, where commented calls of console log, but I get in this case error 'Cannot call method 'log' of undefined', I have to add new method outputlog for tests purpose. It works, but once Tizen emulator reloaded - it also stops working.

So:

  1. Why I cann't call console.log directly from event handlers? I suppose it is a problem of visibility and a problem of pure JS. Am I right?

  2. May be somebody know why method outputlog stops working after reloading of emulator? Here I suppose some specific problem of Tizen app and emulator.

2

There are 2 answers

1
Deryck On

Looks like you put a semicolon and extra curly here:

    messagesremoved: function (removedMessages) {
        //console.log('Message removed');
    }
};  this.smsService.messageStorage.addMessagesChangeListener(messageChangeCallback);
    },
2
Paul S. On

Do you look at the "console" tab in the Chrome console, or only the log in the SDK? Check if both exhibit the same behaviour, possibly it's a communication issue in the SDK.