如何在Cordova插件JS接口中实现promise?

时间:2017-05-05 07:00:38

标签: javascript cordova promise cordova-plugins

下面是我为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]);
  }
};

0 个答案:

没有答案