beautypg.com

2 encapsulate code in functions – Casio Naurtech CETerm Ver.5.5 Scripting Guide User Manual

Page 119

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 119


JavaScript uses “garbage collection” to reclaim memory no longer in use.
Memory occupied by global variables may never be reclaimed, whereas local
variable memory can be reclaimed after a function call completes. Because the
JavaScript engine in CETerm is not reset frequently like a browser JavaScript
engine, it is more likely that poor programming practices could exhaust memory.

5.9.2 Encapsulate Code in Functions

Whenever possible, put multiple script actions within a function. This should
minimize compilations and make it easier to use local variables as described
above. For example, the following actions could be in a script which is bound to
a key-combination:

CETerm.SetProperty( "session1.scanner.upca.enabled", true );
CETerm.SetProperty( "session1.scanner.msi.enabled", false );
CETerm.SetProperty( "session1.scanner.pdf417.enabled", false );
CETerm.PlayTone( 8, 2000, 200 );
CETerm.PlayTone( 8, 1500, 200 );
CETerm.PostIDA( "IDA_SCAN_APPLYCONFIG", 0 );


Or, the actions could be in a function which is loaded with “Load at Startup”

function enableUPCA()
{
CETerm.SetProperty( "session1.scanner.upca.enabled", true );
CETerm.SetProperty( "session1.scanner.msi.enabled", false );
CETerm.SetProperty( "session1.scanner.pdf417.enabled", false );
CETerm.PlayTone( 8, 2000, 200 );
CETerm.PlayTone( 8, 1500, 200 );
CETerm.PostIDA( "IDA_SCAN_APPLYCONFIG", 0 );
{


and the function call, in a separate script, could be bound to the key-
combination:

enableUPCA();

Using the later approach, the function is only compiled once, not each time the
key is pressed. In general, separating the function definitions from the invocation
is a good practice.

This manual is related to the following products: