9 writing efficient scripts, 1 use local variables – Casio Naurtech CETerm Ver.5.5 Scripting Guide User Manual

Page 118

Advertising
background image

N

AURTECH

W

EB

B

ROWSER AND

T

ERMINAL

E

MULATION FOR

W

INDOWS

CE

AND

W

INDOWS

M

OBILE




CETerm Scripting Guide

Page 118


default:
if (responseState === "DATA")
{
// Save character
responseData.push( String.fromCharCode( c ) );
}
break;
}
}

if (responseState === "DONE")
{
// Process message
// Maybe schedule another data detection after processed.
MyProcessMessage( responseData );
responseState = "PRE_STX";
}
else
{ // Schedule another data detection to complete message
sp.WaitForEvent();
}
}



5.9

W

RITING

E

FFICIENT

S

CRIPTS

Good programming practices should be used when developing scripts for
CETerm. In general, it is important to conserve memory, minimize script
compilations, and limit execution times. Please refer to a JavaScript
programming book for more information.

We recommend “JavaScript: The

Definitive Guide (5th Edition)

” by David Flanagan. The following URL is an

excellent starting point for in-depth details about JavaScript and good
programming practices:

http://javascript.crockford.com/

.


5.9.1 Use Local Variables

Whenever possible, use local variables within functions and declare them with
the var keyword, like this:

var status;
var message = "hello";
var i, j, k;

If you fail to use the var keyword, then JavaScript automatically creates a global
variable with that name if it has not already been declared outside a function.

Advertising
This manual is related to the following products: