Netbeans导航器未显示我的JavaScript类方法 [英] Netbeans navigator does not show my JavaScript Class methods

查看:99
本文介绍了Netbeans导航器未显示我的JavaScript类方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些背景,请跳至第二段以获取问题.我曾尝试过像您的典型开发人员这样的许多编辑器,但在将它纳入Dreamweaver之前,我一直以来最喜欢的是Homesite/ColdFusion Studio,我相信你们中的大多数人也会同意我的观点,是的.Dreamweaver.无论如何,我一直在运行Sublime Text 2,没关系,但是我觉得我需要的不是文本编辑器,而是更多的IDE.为此,我已经使用NetBeans几个月了.我开始喜欢它.在家里,我将Mac与TextMate和Coda一起使用,但是我不介意完全迁移到NetBeans,但是有一些问题困扰着我.最值得注意的是,由于某些原因,它的XSL编辑令人讨厌,其次,我遇到了这个JavaScript问题.

Some background, skip to the 2nd paragraph to get to the question. I have tried quite a few editors like your typical developer and still my all-time favorite was Homesite/ColdFusion Studio before it was sucked into Dreamweaver and I trust most of you will agree with me that well, yea.. Dreamweaver. Anyway, I've been running Sublime Text 2 and it's ok but I feel I need more of an IDE than a text editor. To that end I have been using NetBeans for a few months. I'm starting to love it. At home I use a Mac with TextMate and Coda but I wouldn't mind moving to NetBeans completely however there are a few issues that bother me. Most notably its XSL editing is annoying for a few reasons and then secondly this JavaScript issue I've been having.

我喜欢使用ctrl +单击方法等在javascript文件中跳转的功能,例如alt + back可以向后移动,并能够在导航器中查看方法和类的概述.但是我的问题是,在Javascript文件中,NetBeans似乎无法弄清楚我的类及其方法.我使用一种模式来编写我的单例类,这对我来说是必不可少的.我写这样的类如下:

I like the ability to jump around a JavaScript file using ctrl+click on methods and such, alt+back to move back and being able to see the outline of your methods and classes in the navigator. However my issue is that in my Javascript files NetBeans doesn't seem to be able to figure out my class and its methods. I use a pattern for writing my singleton classes that has proved indispensable for me. I write such classes as follows:

// create class to contain code for this page
var FieldMgmt = function() {

    // vars local to the class
    var Fields = {}; // Store the form fields of the class

    return {

        // startup method
        init: function() {
            // initialize properties
            console.log('field management intialized');

            // capture the fields
            this.Fields = Fields = {
                field1: $('select[name=field1]') // field One
                ,field2: $('select[name=field2]') // field Two
                ,field3: $('select[name=field3]') // field Three
            };

            this.initEvents(); // setup events

        }

        // initialize events
        ,initEvents: function(){

        }


        // method 1
        ,method1: function(arg1, arg2){

        }

        // method 2
        ,method2: function(arg1, arg2){

        }

    }; // end return of FieldMgmt

}(); // end FieldMgmt

// start the code for this page
$(document).ready( function(doc){ FieldMgmt.init(); } );

以下是此文件在我的导航器中显示的图片:

And below is a picture of what shows up in my navigator for this file:

如您所见,导航器中没有显示我的任何方法,例如initEventsmethod1method2等.按住ctrl键并单击方法调用也不会转到该方法宣言.因此NetBeans只是不知道这是一个类.以前在其他编辑器中,例如NotePad ++,我也遇到过这种模式的类似问题,并且能够通过修改用于解析文件的正则表达式来使编辑器找出我的文件.

As you can see, none of my methods show up in the navigator such as initEvents, method1, method2, etc. ctrl+click-ing a method call as well doesn't go to the method declaration. So NetBeans just doesn't know this is a class. I've had similar problems with this pattern before in other editors, for instance NotePad++ and I was able to get the editor to figure out my file by modifying the regular expressions used to parse the file.

如果没有此功能,我可以生存,但是如果我可以使用它,那么这将是我的编辑器,因为这些文件可能会变得很大,并能够通过ctrl + click看到所有方法并快速在文件中跳转-ing等会很棒.

I can survive without this feature but if I could get this to work then this would be my editor of choice as these files can get rather large and being able to see all the methods and jump around the file quickly by ctrl+click-ing, etc. would be fantastic.

我正在使用NetBeans 7.3,并且Windows Server 2003上的所有内容都已更新为最新版本.任何帮助将不胜感激.无论如何,我是否需要修改NetBeans以使其了解我的方法?是否有用于此的插件?预先感谢.

I'm using NetBeans 7.3 with everything updated to the latest as of today on Windows Server 2003. Any help would be greatly appreciated. Is there anyway for me to modify NetBeans in order for it to be aware of my methods? Are there plugins for this? Thanks in advance.

推荐答案

在您的示例代码中,您返回一个闭包,该闭包将名为Fields的变量保留为"private",但是您在init中所做的第一件事是通过以下方式公开公开它:声明this.Fields = Fields.发布示例代码后,您最好将FieldMgmt声明为对象文字,并让NetBeans识别它以使其属性显示在导航器中.

In your example code you return a closure that keeps a variable named Fields as "private" but the first thing you do in init is expose it publicly by declaring this.Fields=Fields. With the example code posted you might as well declare FieldMgmt as an object literal and have NetBeans recognize it to have it's properties show up in the Navigator.

var FieldMgmt = {
    init: function() {
    }
    ,initEvents: function(){
    }
    ,method1: function(arg1, arg2){
    }
    ,method2: function(arg1, arg2){
    }
};

这篇关于Netbeans导航器未显示我的JavaScript类方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆