나는이 질문을 여러 번 물었지만 해결책을 찾으려했지만 사용 가능한 질문을 얻지 못했습니다."Uncaught SyntaxError : 예기치 않은 식별자"
나는 자바 스크립트에 매우 초보자입니다. 나는 cordova를 사용하여 안드로이드에서 샘플 계산 응용 프로그램을 만들려고합니다. 이를 위해 필자는 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)
및 calculation.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,
}]
);
}
}
쉼표가 없습니다. – SLaks
이것은 무엇입니까?'console.log ("calculation");' – Isaac
로깅 목적으로 추가했습니다. –