I recently created my own Javascript library, and first used the following template:
var myLibrary = (function () {
var someProp = "...";
function someFunc() {
...
}
function someFunc2() {
...
}
return {
func: someFunc,
fun2: someFunc2,
prop: someProp;
}
}());
The problem is that I cannot really use code completion because the IDE is not aware of the properties returned by the function literal (by the way, I am using IntelliJ IDEA 9).
I looked at jQuery code and tried to do this:
(function(window, undefined) {
var myLibrary = (function () {
var someProp = "...";
function someFunc() {
...
}
function someFunc2() {
...
}
return {
func: someFunc,
fun2: someFunc2,
prop: someProp;
}
}());
window.myLibrary = myLibrary;
}(window));
I tried this, but now I have a different problem. The IDE is not really dialing myLibrary.
Now I solve the problem as follows:
var myLibrary = {
func: function() { },
func2: function() { },
prop: ""
};
myLibrary = (function () {
var someProp = "...";
function someFunc() {
...
}
function someFunc2() {
...
}
return {
func: someFunc,
fun2: someFunc2,
prop: someProp;
}
}());
But that seems pretty awkward, and I can't figure out exactly how jQuery does it. Another question I have is how to handle functions with an arbitrary number of parameters.
, jQuery.bind 2 3 , IDE, , . , 0 1 . IDE , . ?
, Idea9, jQuery . , , .