# Code completion for JavaScript functions

The code completion provided by JSEclipse allows the developer to become more productive by suggesting function and variable names as the code is written. The suggestions range from the standard JavaScript functions to the variable name typed a few rows above.

The code completion mechanism recognizes the correct type of the functions and variables and proposes them as needed. Also, words from the active file are suggested, or functions and methods from the entire project.

Code completion can be accessed and used in several ways:

1. Automatically - when using class methods, either custom or predefined, the code completion window will appear automatically.

2. Manually - when using code completion for function or variable names in the current file, the suggestions are not displayed automatically. To display them, press CTRL+SPACE, or right-click the already typed letters and select Content Assist:

The code completion provided by JSEclipse suggests functions from the defined classes and from the classes they extend. To access code completion for class methods, simply create a new instance of the class, and type the new object name followed by a dot. The list of available methods for that particular object will be displayed:

Parameters for the functions that need them are also offered by code completion. The parameter name, as requested by the function is displayed both when the function itself is suggested, and after selecting it, as tool-tip text:

Function and variable names already defined in the current file can be quickly inserted through JSEclipse's code completion. Simply start typing the function name, and access the code completion option. All possible entries will be suggested:

JSEclipse also provides code completion for standard JavaScript objects and methods. Currently supported are all the methods in the following classes:

- window

- string

- screen

- object

- navigator

- element

- document

When using a method of a class that extends an existing class, methods from the parent class and the class that extends it are suggested. If the library is properly commented, the comments are also displayed:

### Code completion for the getElmentById method

JavaScript is mostly used in conjunction with HTML files to add functionality. Either you just want to display a calendar, hide or display a div with some information, or more complex element manipulation, you go almost the same way:

1. In the HTML file you include the JavaScript file, using a <script src=""></script>tag.

2. In the JavaScript file you use the document.getElementById method to access the element.

Each time you use this method, you must check the HTML file to see what is the exact ID. JSEclipse helps in this task by inspecting all HTML files that include the JavaScript file you're working on and suggesting a list of ID's. All HTML files that exist in the same project and include the script will be parsed, and ID's from all will be suggested:

### Code completion limitations

1. New class instance creation - In order for JSEclipse to correctly recognize the current object's type, you must define it as an instance of the class explicitly, using the new keyword:
   var new_object = new class_name([parameters]);
   Other ways of creating a new instance are not supported. For example, in the code sample below, the instance john is correctly recognized as being an object of person type, while john2 would never be (its type can only be evaluated at runtime). Therefore, for john you have code completion: