JavaScript is not a
strongly-typed programmed language. One may define a variable as simple as:
var p;
In this example p is just
a variable with undefined type. It may be used as number, string or object. So
Rapise has no idea of how to deal with it. So if you type a dot after “p.” no code-completion window appears.
Rapise scans for
variable definitions when one saves the .js source file. So if anything goes
wrong then first thing is to save the file.
![]()
Another essential
place to check when typing code is “Warnings” screen. It is updated when you
save the file and if there are any syntax errors in the current source text
warnings screen will be populated:
![]()
There are several ways
of explaining variable type.
First, is static assignment.
Suppose you specify some constant value when defining a variable:
var p="some string";
In this case Rapise
knows the type of p. So it would assist you when you type a dot “.” after p:
![]()
In some cases variable
type is not clear from its definition or assignments is not static:
var v1 = input;
var v2;
To deal with such
cases the code should be instrumented. For example, if we know that input is
string and v2 will be used as number then we may explain it to Rapise by
placing variable type using special comment: /**<var_type*/ right
together with var definition. It should be placed right either between var keyword
and variable name or right after an assignment operation (=), if
any. I.e.:
var v1 = /**string*/input;
var /**number*/v2;
So we will have code
completion properly informed:
![]()
Another common case is
a function parameter. Once function is defined like that:
function my_func(patient_index, patient_name)
{
}
The type of parameters
patient_index and patient_name are not known, but may be explained in a
similar way:
function my_func(/**number*/patient_index, /**string*/patient_name)
So it becomes known to
Rapise:
![]()
Code completion for
variable names is useful when you have multiple variables or function
parameters and need to type them quickly. In this case Alt+Space keyword
combination will bring up a list of variables and functions starting with just
typed keyword.
For example, here I
pressed Alt+Space to show list of functions starting with just typed “find_”
prefix:
![]()
And then I pressed it
to find a variable for “pa” prefix:
![]()
How to force code completion
Code completion is
activated when you press “Alt+Space” keyword combination or when you press dot
“.” key right after variable with known type.