javascript – “未捕获的SyntaxError:意外的标识符”

我知道这个问题很多次,但我试图找到解决方案,但没有得到可用的SO问题.

我是Javascript的新手.我正在尝试使用cordova在android中创建示例计算应用程序.为此,我创建了cordova插件.但我不断得到两个问题.

"Uncaught SyntaxError: Unexpected identifier", source: file:///android_asset/www/js/index.js (36)

这里是index.java代码和错误目标performCalculation()的第一行.

    var app = {

// Application Constructor
initialize: function() {
    this.bindEvents();
},
bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);
    document.getElementById("btnCalculate").addEventListener("click", performCalculation);
},
onDeviceReady: function() {
    app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
    var parentElement = document.getElementById(id);
    var listeningElement = parentElement.querySelector('.listening');
    var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');

    console.log('Received Event: ' + id);
}

performCalculation: function (){
    console.log("in index.html");
    var success = function() {
        alert("Success");
    };
    var error = function(message) {
    alert("Oopsie! " + message);
    };
    performAddition(20,10,success,error);
}

};  
app.initialize();

这是我得到的第二个例外.

"Uncaught SyntaxError: Unexpected token .", source: file:///android_asset/www/js/calculation.js (3)

这是计算代码.js

var calculationPlugin = {
console.log("calculation");
    performAddition: function(first_number, second_number, successCallback, errorCallback) {
    console.log("addition");
        cordova.exec(
            successCallback, // success callback function
            errorCallback, // error callback function
            'CalculationPlugin', // mapped to our native Java class called "CalculationPlugin"
            'addition', // with this action name
            [{                  // and this array of custom arguments to create our entry
                "firstNumber": first_number,
                "secondNumber": second_number,

            }]
        );
     }
}

解决方法:

第一个语法错误

在receiveEvent函数之后,您缺少“,”.

第二个语法错误

计算插件是一个对象,因为你有控制台,抛出错误.从该对象中删除控制台.

相关文章

公司前端界面用的是vue,我要嵌入到Android中生成App第一步:...
Q:我用cordova开发项目,想在app内跳转外部链接,安装了cord...
我正在使用https://github.com/arnesson/cordova-plugin-fir...
一、Cordova的基础点在混合式应用中,我们通过现有的Cordova...
cordova自定义插件注意:存放自定义cordova插件目录不能有空...
一、问题VueAPP中有一个文件下载功能,用了各种方法来实现下...