【问题标题】:Is it possible to declare argument types in javascript?是否可以在 javascript 中声明参数类型?
【发布时间】:2010-01-16 09:26:44
【问题描述】:

如果没有自动完成功能,我会很笨拙,当我声明一个将“对象”作为参数而不是实际类型的函数时,自动完成功能当然不能工作。

有没有办法做到这一点?我怀疑答案是否定的——在这种情况下,如果没有自动完成功能,您将如何管理?

【问题讨论】:

    标签: javascript


    【解决方案1】:

    Microsoft 正在使用特殊的带注释的 JavaScript 源文件在 Visual Studio 中改进代码完成。这对于许多程序员大量使用的库应该很有效。

    您可以在此处查看带注释的 JQuery 版本: http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.3.2-vsdoc2.js

    attr 函数的文档,例如看起来像这样:

    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>
        ..
    }
    

    然而,将所有这些 XML 写入您自己的 JavaScript 文件可能有点过头了。

    【讨论】:

    • 这会出现在 VS 2010 RTM 中吗?
    【解决方案2】:

    嗯,Visual Studio 和 Aptana 提供的 Intellisense 选项不是很高级,但作为使用 javascript 编程,它们目前提供的 Intellisense 级别对我来说已经足够了。也许你应该看看 Aptana Studio。它也有免费版本。

    编辑:

    我所知道的最好的 JavaScript 编辑器肯定是 Aptana。因为它还为不同的 JavaScript 库提供了很多支持。您应该下载 Visual Studio 的 Hotfix 更新以获得 jQuery Intellisense 的便利性,但此选项在 Aptana 中与 Prototype、ExtJs、Microsoft 等其他库一样工作得很好。

    【讨论】:

      【解决方案3】:

      我已经开发 Javascript 应用程序 5 年了,我使用过 aptana、visual studio 等。我会说最适合这项工作的工具是 IntelliJ。自动完成功能非常丰富和智能。我也喜欢 Go To Declaration 功能,语法着色。语法检查,感觉就像在 Javascript 中使用 resharper。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-03-31
        • 2015-08-20
        • 2020-03-05
        • 1970-01-01
        • 2019-12-06
        • 2020-11-18
        • 1970-01-01
        相关资源
        最近更新 更多