I use Vim as well.

On 11-01-27 09:19 AM, Acaz Souza Pereira wrote:
These IDEs, when i place another js file to page, the autocomplete know the functions and variables of that js file?

Vim has some support for autocompletion (vim calls it omnicomplete), but it's pretty rudimentary, and I think based on parsing via regular expressions, as opposed to an AST. For example, if I have an object foo = {a:1}, and I type "foo." and use omnicomplete, it will list everything in the file that it parses as an identifiers. So it's not context-aware, but still, it can help you save you some keystrokes.

Unfortunately, because JavaScript is a dynamically typed language, building an IDE with proper autocomplete support is much more challenging than with a statically typed language like Java. For example, if I have a function foo(a){print(a)}, then to determine the type information of a, I would need to look at all the call sites of foo to see what is the type of the value that is being passed into foo. If it is a literal (1, "string", {object:2}), then I will know the type of a. But if it's a variable b, then I would need to trace back further to see the type of the value that has been assigned to b. And if that assignment takes place in an if/else block, such that the if block assigns a different type to b than the else block, then there would in fact be a set of possible types for b. Furthermore, if b is an object, then its properties can be changed dynamically, which is difficult to track. All of this is just to illustrate that building an editor that is aware of type information for each variable is non-trivial, and there's a limit to what can be known due to the dynamically typed nature of the JavaScript language.

One interesting approach I've seen in some IDEs (Aptana, and I think some others) is to accommodate developers who program in a statically-typed style. So, for every variable, you would only make assignments to that variable of the same type. The IDE then supports annotations using the ScriptDoc syntax. So, basically the IDE allows the developer to tell it what will be the type of each variable. But still, this is a difficult thing to do well.

Cheers,

Jake

--
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to