Note that personally I prefer superior JsDuck over JsDoc for actual HTML documentation generation.
This is because naive source code scanners have very hard time to determine module exports and classes from this kind of source code and as far as I know, no IDE supports RequreJS natively yet. JsDoc class and namespace hints are especially needed when you are using something like RequireJS for defining your modules. Do this by following the JsDoc best practices and you’ll be lucky and the same type information can be utilized for generating autocompletions too. If you have any self respect you document your source code with comments. JsDoc was originally created to generate Javadoc like API documentation for Javascript projects. Basically you write something like in /** */ comment blocks and it is picked up.
JsDoc is a loosely followed convention to annotate Javascript with source code comments to contain references about packages, namespaces, singlentons, etc. When project size and number of developers grow, static typing becomes more and more preferable as it decreases the cognitive load needed to work with the codebase, reducing human errors. Please note that autocompletion is not the only reason to have static typing support or type hinting. To make the editor support autocompletion one needs to integrate a source code scanner plug-in which extracts the type information and turns it to the native symbol database format supported by the editor. sublime-completions files and Aptana Studio Javascript autocompletions. By using these type hints your text editor can know that $ is actually jQuery and can guess what kind of functions it could provide.įirst of all, most text editors have their own type information format and files which are generated from the source code or entered as manually maintained files. There exist several ways to annotate Javascript source code or overlay type information over it. Introducing type information into Javascript Thus, there is no single solution to extract the classy type information, even run-time. There isn’t one right way, but many incompatible ways. Prototypial inheritance gives great freedoms – leading to the sad state of the things that each Javascript framework has invented their own way to declare classes, modules and namespaces. What makes things even more worse and sets Javascript apart from Ruby and Python is the lack of native support of classes and modules.
Thus, your text editor cannot know how to autocomplete your typing because it cannot know what autocompletions there are available. This makes Javascript lighter to write, but it also effectively means that during writing the code the information about the variable contents is not really available. In statically typed systems like Java you declare the type of the variables when you introduce them, like int i or M圜lass foo. until the code is actually executed in the web browser. Javascript does not have Java-like static typing system, meaning that it’s not possible to know what’s the type variables of like this, $, jQuery, etc. Why autocompletion for Javascript is so hard