简体   繁体   中英

Cordova Plugins

Can someone explain me how does a structure of a javascript file written to execute a custom plugin work, for example I know that

exec(<success function>,<failure function>,<service>,<action>,<args>)

this function is used to call the native where service is the plugin class name and action is the method that needs to be called in that class. What I am failing to understand is that what does this structure do for example

cordova.define("cordova/plugin/pluginName",
function(require,exports,module){
var exec = require("cordova/exec")
pluginName.prototype.methodName = function()

I am unable to understand what is happening here ?

You don't have to use cordova.define anymore, that's added automatically on plugin install

From the doc :

Do not wrap the file with cordova.define, as it is added automatically. The module is wrapped in a closure, with module, exports, and require in scope, as is normal for AMD modules.

var exec = require("cordova/exec") just loads the cordova.exec module into exec, if you don't do this you can call your plugin with cordova.exec(<success function>,<failure function>,<service>,<action>,<args>) instead of just doing exec(<success function>,<failure function>,<service>,<action>,<args>)

pluginName.prototype.methodName = function() just creates a methodName function for your pluginName, so it makes possible that the user can call your plugin method like pluginName.methodName()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM