I'm creating a jQuery plugin. So far it's working fine, but I'm having doubt about the way I'm doing things:
jQuery.fn.myMethod = function() {
return this.each(function(){
MyScope.doSomething(jQuery(this).attr("id"));
});
};
var MyScope = {
// The functions contained in MyScope are extremely linked to the logic
// of this plugin and it wouldn't make a lot of sense to extract them
doSomething: function(id){
// something
doSomethingElse(23);
// some more code
doSomethingElse(55);
},
doSomethingElse: function(someInt){
// some code
}
};
I use MyScope to store all my "private" functions. I don't want the user to be able to go $("p").doSomething()
, but I do need to use them.
I could move everything in the myMethod
function, but it would create a 100 lines long function and people would hate me for it.
What's the best practices in this situation? Are there any great tutorials out there regarding this?