Project Description
Ever wondered how to get annotation for JavaScript if you use a module loading system like require.js? Use this small script to create stub files that can be used by nearly all IDE's. 

This is a small Javascript that creates namespaces and property-stubs from JSDoc-style comments for easier IDE autocomplete. You can annotate variables with the JSDoc @type parameter. These variables will then be displayed by the IDE as the correct objects (which is normally a pain in the a** because of the complexity and freedom of javascript code).
Please run the file with Windows Scripting Host.

The main problem why I created this project was this: Module Pattern


Example:

define("TestNamespace", function () {
	/** @namespace TestNamespace */
	function TestNameSpace() {
		/** 
		 * @class TestNamespace.Test
		 * @constructor
		 * @name Test
		 * @param String testParam
		 */
		this.Test = function (testParam) {
		};
	
		/** 
		 * @type String
		 * @memberOf TestNamespace.Test
		 * @name testProperty
		 */
		this.testProperty = "";
	
		/** 
		 * @memberOf TestNamespace.Test
		 * @returns Boolean
		 */
		function VirtualTestFunction() {
			
		}
	}
	return new TestNameSpace();
});

Will result in this output file:

/** @namespace TestNamespace */
var TestNamespace = {};
	/** 
	 * @class TestNamespace.Test
	 * @constructor
	 * @name Test
	 * @param String testParam
*/
TestNamespace.Test = function(testParam) {

};
	/** 
	 * @type String
	 * @memberOf TestNamespace.Test
	 * @name testProperty
*/
TestNamespace.Test.testProperty = "";
	/** 
	 * @memberOf TestNamespace.Test
	 * @returns Boolean
*/
TestNamespace.Test.VirtualTestFunction = function() {
return new Boolean();
};

Nearly all good IDE's (e.g. JavaScript Eclipse or WebStorm) can now autocomplete custom properties:

/** @type TestNamespace.Test */
var someObject = require("TestNamespace");

// most IDE's got autocomplete now without 
// initiating the actual object directly...
someObject.testProperty;

Last edited Mar 7, 2012 at 8:59 PM by WalaWala, version 22