开发者

Is it possible to declare argument types in javascript?

I am crippled without auto-completion, and when I declare a function that takes 'objects' as arguments instead of the actual types, of course auto-completion cannot work.

Is there some way to do this? I suspect the answer is 'no' - in which case, how do you ma开发者_高级运维nage without auto-completion?


Microsoft is working on better code completion in Visual Studio using special, annotated JavaScript source files. This should work great for libraries that are used heavily by lots of programmers.

You can take a look at an annotated version of JQuery here: http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.3.2-vsdoc2.js

The documentation for the attr function e.g. looks like this:

attr: function( name, value, type ) {
    ///    <summary>
    ///        Set a single property to a computed value, on all matched elements.
    ///        Instead of a value, a function is provided, that computes the value.
    ///        Part of DOM/Attributes
    ///    </summary>
    ///    <returns type="jQuery" />
    ///    <param name="name" type="String">
    ///        The name of the property to set.
    ///    </param>
    ///    <param name="value" type="Function">
    ///        A function returning the value to set.
    ///    </param>
    ..
}

Writing all this XML in your own JavaScript files may however be somewhat overkill.


Well, Visual Studio and Aptana give not pretty advanced Intellisense options but as programming with javascript, the intellisense level they are currently providing is enough for me. Maybe you should check out Aptana Studio. It has free version as well.

Edit :

The best JavaScript editor I know is Aptana for sure. Because it comes with a lot of support for different JavaScript libraries as well. You should download Hotfix update for Visual Studio to have the convenience of jQuery Intellisense but this option works pretty well in Aptana as with other libraries like Prototype,ExtJs, Microsoft, etc.


I have been developing Javascript applications for 5 years now, I have used aptana, visual studio etcetera. I will say that the best tool for the job is IntelliJ. The auto-complete is very rich and intelligent. I also love the Go To Declaration feature, syntax coloring. Syntax check, It feels like using resharper in Javascript.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜