- Syntax Highlighting
- Code Completion (In a single JavaScript file or across multiple in the same folder)… NOTE: JSDT allows code completion within a single file, but breaks down when you have multiple JavaScript files.
- Validation
- Support for jQuery, Prototype, YUI, Dojo, etc
Example #1 that works
var foo = {
myMethod: function(){
},
anotherMehtod: function(){
}
}
Also, if you setup all of your methods to be global then it will pick up those methods as well (not recommended).
Another way you can do it is to create a class such as:
Example #2 that works
function foo() {
}
function bar(a, b){
};
foo.prototype.b = bar;
var x = new foo();
x.b
In the above example the key parts to recognize is that you have to define the class and function separately and then relate them using prototype as in foo.prototype.b = bar, where b will be the name of the method when accessing it via the class and bar is the name of the original method. Although I don’t like the extra work required to setup the class, since it provides me with code completion (a feature I dearly love) I find the pain to be sufferable.
So now that I have told you what works, what doesn’t work when declaring namespaces and functions? I have provided examples of those below:
Example #1 that doesn’t work
var foo = new function(value){
this.myMethod= function(){
}
}
Example #2 that doesn’t work
function foo(value){
this.myMethod= function(){
}
}
Example #3 that doesn’t work
var foo = new function() {
}
function bar(a, b){
};
foo.prototype.b = bar;
var x = new foo();
x.b