简体   繁体   English

Cordova 插件

[英]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有人可以解释一下为执行自定义插件而编写的 javascript 文件的结构如何工作,例如我知道

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.此函数用于调用本机,其中 service 是插件类名,action 是需要在该类中调用的方法。 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您不必再使用cordova.define ,它会在插件安装时自动添加

From the doc :文档

Do not wrap the file with cordova.define, as it is added automatically.不要用cordova.define 包装文件,因为它是自动添加的。 The module is wrapped in a closure, with module, exports, and require in scope, as is normal for AMD modules.模块被包裹在一个闭包中,模块、导出和要求在范围内,这对于 AMD 模块来说是正常的。

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>) var exec = require("cordova/exec")只是将cordova.exec模块加载到exec中,如果你不这样做,你可以用cordova.exec(<success function>,<failure function>,<service>,<action>,<args>)而不是仅仅执行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() pluginName.prototype.methodName = function()只是为你的 pluginName 创建一个 methodName 函数,这样用户就可以像pluginName.methodName()一样调用你的插件方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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