下面是我为cordova插件构建的JS接口框架。我是Javascript的新手,想要实现承诺。我怎么能这样做?
var exec = require('cordova/exec');
module.exports = {
methodA : function(initData, successCallback, failureCallback) {
exec(successCallback,
failureCallback,
"MyPlugin",
"methodA",
[initData]);
},
methodB : function(successCallback) {
exec(successCallback,
null,
"MyPlugin",
"methodB",
[]);
},
methodC : function(key, data, successCallback, failureCallback) {
exec(successCallback,
failureCallback,
"MyPlugin",
"methodC",
[key, data]);
},
methodD : function(key, successCallback, failureCallback) {
exec(successCallback,
failureCallback,
"MyPlugin",
"methodD",
[key]);
}
};