Ask a Question

How can I declare a static variable in java script

SOLVED
Preetha
Occasional Contributor

How can I declare a static variable in java script

How can I declare a static variable in java script?

 

function CompareClassicCAT(img1,img2)
{
 var fileName, sheetName, colNumber,rowNumber, content;
fileName=Project.ConfigPath+"\AutoDataSource\\CATRegressionCompareTestResults.xlsx";
rowNo = 1;
colNo1=2;
colNo2=3;
sheetName="Test_Result";
if(Regions.Compare(img1,img2))
{

AddDataToExcelFile(fileName, sheetName, rowNo, colNo1, img1);
AddDataToExcelFile(fileName, sheetName, rowNo, colNo2, "Identical");
Log.Message(img1 + " is identical :)");
rowNumber++;
}
else
{
AddDataToExcelFile(fileName, sheetName, rowNo, colNo1, img2);
AddDataToExcelFile(fileName, sheetName, rowNo, colNo2, "NOT Identical");
Log.Message(img1 + " is NOT identical :)");
rowNumber++;
}
}

 

 

calling this function and the rowNumber , colNo1,colNo2 should not reinitialise.

3 REPLIES 3
shankar_r
Community Hero

declare the variable in global so it won't reset.


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

Preetha
Occasional Contributor

Ok But where to initialise the variable as i need to initilise it inside my function and when I call that function again it is reinitilising.

Preetha
Occasional Contributor

I got the solution.. 

initialise the variable outside the function as functionname.variable=value;

 

 

CompareClassicCAT.rowNo = 1; //static variable
CompareClassicCAT.colNo1= 2; //static variable
CompareClassicCAT.colNo2= 3; //static variable


function CompareClassicCAT(img1,img2)
{

var fileName,rowNo,colNo1,colNo2, sheetName, content;
fileName=Project.ConfigPath+"\AutoDataSource\\CATRegressionCompareTestResults.xls";

sheetName="Test_Result";

if(Regions.Compare(img1,img2))
{
CompareClassicCAT.rowNo++;
AddDataToExcelFile(fileName, sheetName, CompareClassicCAT.rowNo, CompareClassicCAT.colNo1, img1);
AddDataToExcelFile(fileName, sheetName, CompareClassicCAT.rowNo, CompareClassicCAT.colNo2, "Identical");
Log.Message(img1 + " is identical");

}
else
{
CompareClassicCAT.rowNo++;
AddDataToExcelFile(fileName, sheetName, CompareClassicCAT.rowNo, CompareClassicCAT.colNo1, img2);
AddDataToExcelFile(fileName, sheetName, CompareClassicCAT.rowNo, CompareClassicCAT.colNo2, "NOT Identical");
Log.Message(img1 + " is NOT identical");

}
}

cancel
Showing results for 
Search instead for 
Did you mean: