I am developing a PhoneGap application for Android OS. I want to my application to be designed as most extendable as possible. Therefor I am writing all my modules as plgins, save them in one map and then I would like to use them in my HTML page. I wrote this code in MyJS.js file:
var map = {};
// Allow jQuery to cash the cordova.js
$.ajaxSetup({ cache: true});
$.getScript("cordova-2.6.0.js",function(){
var AccelerometerSensor = {
accelJSONObj:cordova.require("cordova/plugin/Acceleration"),
accelPGAPSens:cordova.require("cordova/plugin/accelerometer"),
color:'#FF8C00',
sensorID:'Accelerometer',
// Flag indicates whether this sensor type is supported by the device or not.
availability:null,
isAvailable:function() {
accelPGAPSens.getCurrentAcceleration(
function(x){availability = true;},
function(){availability = false;});
},
}
})
.done(function(script, textStatus) {
map["Accelerometer"] = this.AccelerometerSensor;
alert('done');
})
.fail(function(jqxhr, settings, exception) {
alert('fail');
});
Now I want to call the isAvailable function, so I wrote this code:
map["Accelerometer"].isAvailable()
But I got a TypeError:
"cannot call method 'isAvalable' of at undefined..."
What am I doing wrong? can anyone please show me what I have to do?
Thanks!!!