按照this SO线程中的示例,我试图实现此功能:
var fn = "cordova.plugins.photoLibrary.saveImage";
if (isVideo) fn = "cordova.plugins.photoLibrary.saveVideo";
window[fn](entry.toURL(), album, success, error);
这会引发以下错误:
TypeError: undefined is not a function (near '...window[fn]...')
cordova函数是否不属于全局窗口名称空间的一部分?
答案 0 :(得分:0)
根据https://eslint.org/docs/2.0.0/rules/dot-notation,这是数组符号的有效用法:
var pluginName = (condition ? "saveVideo": "saveImage");
cordova.plugins.photoLibrary[pluginName](entry.toURL(), album, success, error);