var currentApple;
if (appleTab == Lifeline) {
currentApple = /* etc. */
'currentApple' is already defined showing in jslint
-
29-06-2022 - |
Domanda
I have have some js code; in that I ran the js lint. I have this error:
'currentApple' is already defined
Do I need to remove var currentApple
from else
to make it work?
I'm providing my code below:
if(appleTab == Lifeline){
var currentApple = appleWorklist.getcurrentAppleTime("currentAppointmentcurrentAppleTime");
fo.allApples = currentApple;
}
else
{
var currentApple = appleWorklist.getcurrentAppleTime("CalendarcurrentAppointmentcurrentAppleTime");
fo.allApples = currentApple;
}
Soluzione
Altri suggerimenti
there is no blockscope in javascript, so currentApple
in your code snippet is basically the same thingy.
from Douglas Crockford's bible, paragraph Variables:
JavaScript does not have block scope, so defining variables in blocks can confuse programmers who are experienced with other C family languages. Define all variables at the top of the function.
Just declare every used variable once with a var statement at the start of your function.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow