JavaScript

# JavaScript mode

JavaScript mode is intended for editing of external JavaScript documents (suffix .js). It may also sometimes be a better choice when you are editing JavaScript inside an HTML document. Select JScr in the mode menu in the status bar to manually switch to JavaScript mode.

JavaScript mode provides keyword coloring, word completion, and the basic editing features, indent on return, electric semicolon, electric braces, and special indent for case label.

## Word completion

In JavaScript mode completions of a number of statements are available: function, for, while, switch, case, do, if, and else. Typing ctrl-tab after typing any of these statements expands them to a template. Two examples:

Typing

    for

and then typing ctrl-tab gives

    for (|; •; •) {
        •
    }
    •

Typing

    while

and then typing ctrl-tab gives

    while (|){
        •
    }
    •

## Funcs menu

The funcs menu lists all functions defined in the document. Selecting a function in the menu lets you jump to it.

## Cmd-double-clicking

Cmd-double-clicking on a keyword or builtin property or function makes Alpha jump to a JavaScript reference guide. This requires that you install the JavaScript reference for Alpha by Wolfgang Haeuptli.

The cmd-double-clicking also works in HTML mode.

## Preferences

The JavaScript preferences dialog is opened using Config->JScr Mode Prefs->Preferences.

Electric braces
Enabling Electric braces tells Alpha to treat the left or right brace '{', '}' keys as special keypresses which enter the '{' or '}' character, followed by a carriage return and then indent the following line correctly. Note! For the electric braces to work you must select your keyboard in the dialog Config->Preferences->System Preferences->International.
Electric semicolon
Enabling Electric semicolon tells Alpha to treat the semicolon key ';' as special keypresses which enters the ';' character followed by a carriage return and then indents the following line correctly. The ';' key is context-dependent so you can still enter a for( ; ; ) loop in JavaScript code without Alpha messing things up.
Indent on return
Enabling Indent on return tells Alpha to indent the following line automatically whenever you press return.
Special indent for case label
Enabling Special indent for case label tells Alpha to indent the case lines inside switch differently.

## JavaScript in HTML mode

The JavaScript support in HTML mode is the same as in JavaScript mode, except that there is no special indent for case label, and the funcs menu has another functionality in HTML mode. You can say that between <SCRIPT> tags in an HTML document Alpha behaves as if it were is JavaScript mode.

Previous page Next page