Bug 202932 - Support for Module pattern
Support for Module pattern
Status: NEW
Product: javascript
Classification: Unclassified
Component: Navigation
7.3
All All
: P2 with 4 votes (vote)
: 7.3
Assigned To: Petr Pisl
issues@javascript
:
: 156553 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-10-01 18:34 UTC by c69
Modified: 2013-07-04 09:12 UTC (History)
3 users (show)

See Also:
Issue Type: ENHANCEMENT
:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description c69 2011-10-01 18:34:47 UTC
var MODULE = (function () { 
    var my = {}, 
        privateVariable = 1; 
     
    function privateMethod() { 
        // ... 
    } 
     
    my.moduleProperty = 1; 
    my.moduleMethod = function () { 
        // ... 
    }; 
     
    return my; 
}());

http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth
http://www.yuiblog.com/blog/2007/06/12/module-pattern/
http://snook.ca/archives/javascript/no-love-for-module-pattern


Currently, when you use it - neither private, nor public methods appear in code navigator. Would be nice if they did (like in WebStorm IDE).
Comment 1 Petr Pisl 2011-10-04 12:26:28 UTC
Yes it would be nice to support this approach. I'm marking as enhancement.
Comment 2 brettryan 2012-02-16 03:34:01 UTC
What I think is a better pattern that does work as expected is the following pattern which is similar.

This pattern will show in code completion correctly and have the correct documentation presented while allowing for the same pattern and IMHO better encapsulation as all your exports are in one place (the return statement).


MODULE = (function() {
    
    var privateVariable = 1;

    function privateMethod() {
        // ...
    }

    var publicMethod = function() {
        // ...
    }

    return {
        /**
         * This is a readonly property
         * @property
         */
        moduleProperty: function() { return privateVariable; },
        /**
         * This is a writable property
         * @property
         */
        moduleProperty2: function(newVal) {
            return newVal ? privateVariable = newVal : privateVariable;
        },
        /**
         * @function
         */
        publicMethod: publicMethod
    }
})();
Comment 3 c69 2012-12-01 19:57:32 UTC
NB7.3 still cannot parse such code. Shouldn't new JS engine have addressed this?
Comment 4 c69 2012-12-02 12:55:36 UTC
*** Bug 156553 has been marked as a duplicate of this bug. ***
Comment 5 c69 2012-12-05 21:17:32 UTC
Increased Priority (i am considering switching to WebStorm, if this feature would not be implemented), and updated milestones and platform field.
Comment 6 vezea 2013-03-01 08:02:45 UTC
This seems to be more of a bug than an enhancement.  NB7.3 seems to have taken a huge step backward with regard to the Javascript Navigator.  NB7.2 wasn't great but it was usable.  Now it seems like hardly anything is showing up in the navigator.

Even the simplest sort of closure pattern seems to befuddle the navigator.  For example:

	(function closureFunction(){
	
		var scalarVariable = "Invisible in navigator!";
		var arrayVariable = ["Invisible!"];
		
		var objectVariable = {}; // Object variable is visible for some reason
	
		function invisible(){
			// Invisible in navigator
		}
	
		var functionVariable = invisible;	
	})();

Yields ONLY the following in the navigator:

	objectVariable

At least the previous versions of NetBeans recognized all named functions, regardless of scope, which allowed us to assign dummy names to otherwise anonymous closures (e.g. "closureFunction" above) and use the navigator to jump to them.

We've been looking forward to these new Javascript features in NB7.3, but it's virtually impossible to see them when we can't even navigate around our code.

In any event, thanks for all the great work on this IDE to date!
Comment 7 Vladimir Riha 2013-03-01 08:07:51 UTC
Please check issue 226480, which fixes your issue. It is targeted to the next patch.
Comment 8 flod1 2013-03-06 08:07:27 UTC
Hy

The Netbeans Navigator doesn't find my object,function and variables.

I use a Pattern like this:
********* my/init.js *****************

My = window.My || {};

********* my/test.js *****************

My.test = {
   test: true,
   testFunction: function(){
       return "hallo";
   }
}

*************************************
If i work in the text.js, the Navigator show nothing.
if i work in the init.js, the Navigator show me my object
Comment 9 ragamufin 2013-07-04 07:18:44 UTC
I recently ran into this myself and with some help from StackOverflow figured a way around it. The way the code you guys is structured, we are really dealing with objects and not a class or instance thereof. Give that, you can simply move the first lines around in order for you to still maintain the scoping/private variables and yet still have a global object containing your methods. So restructuring the code you posted would look like the code below and most importantly everything shows up in the navigator:

(function() {

    var privateVariable = 1;

    function privateMethod() {
        // ...
    }

    var publicMethod = function() {
        // ...
    }

    MODULE =  {
        /**
         * This is a readonly property
         * @property
         */
        moduleProperty: function() { return privateVariable; },
        /**
         * This is a writable property
         * @property
         */
        moduleProperty2: function(newVal) {
            return newVal ? privateVariable = newVal : privateVariable;
        },
        /**
         * @function
         */
        publicMethod: publicMethod
    }
})();
Comment 10 brettz9 2013-07-04 09:12:50 UTC
It's useful to have workarounds, but ideally one should not need to program to the IDE (and sometimes one just wishes to view others' code)...


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo