What is the best way to implement module pattern, while the module code depends on third party libraries like jQuery for example?
var someModule = (function(){
//private attributes
var privateVar = 5;
//private methods
var privateMethod = function(){
return 'Private Test';
};
return {
//public attributes
publicVar: 10,
//public methods
publicMethod: function(){
return ' Followed By Public Test ';
},
//let's access the private members
getData: function(){
//make ajax call and do some processing and generate output
return privateMethod() + this.publicMethod() + privateVar;
}
}
})(); //the parens here cause the anonymous function to execute and return
someModule.getData();
My question is: I am planning to put all the code in a library like fashion in a javascript file.
As you see in the getData() method, I plan to make ajax calls. I want to use jQuery library for this. Now how do I code a javascript module, while relying on jQuery ?
Should I make my whole library a jQuery plugin instead?