timdelawe
timdelawe

Reputation: 15

Named callback function doesn't work

I'm new to JavaScript and trying to use callback functions in a JS file for phonegap. The plugin I want to use is this: documentation .

The following syntax is given:

bluetoothle.initialize(successFunction, errorFunction, parameter)

I understand that successFunction is the function called whene initialize has succeeded. So I tried two ways. This one works:

bluetoothle.initialize(function()
                    {
                        document.getElementById("testvalue").value += "\ninitialized";
                    }, function(){}, {"request": true, "statusReceiver": false});

And this doesn't:

var event = 
{
    onInitialized: function()
                    {
                        document.getElementById("testvalue").value += "\ninitialized";
                    },                      
    onError: function(message)
                {
                    document.getElementById("testvalue").value += "\nError: " + message;
                }
};
bluetoothle.initialize(event.onInitialized, event.onError, {"request": true, "statusReceiver": false});

I guess all I changed is naming the callback function. What is wrong here?

Upvotes: 0

Views: 82

Answers (1)

rory
rory

Reputation: 1438

There seems to be an inconsistency with the plugin code:

var bluetoothle = {
  initialize: function(successCallback, params) {
    cordova.exec(successCallback, successCallback, bluetoothleName, "initialize", [params]);
  },

I'm only seeing one param here. I suggest you try an earlier version

Upvotes: 1

Related Questions