[jQuery] Plugin model question
When a point is completely missed in the documentation, it's usually because it's obvious to the writer and almost all the readers.
I'll dive in and ask the obvious.
The plugin skeleton shown below is taken from the plugin model overview at :
http://jquery.com/plugins/Authoring/
new function() {
var privatedata = 42;
$.fn.mypluginmethod = function() {};
$.myplugin = {
publicmethod1: function() {},
publicmethod2: function() {}
};
function privatehelper() {}
}();
1 - I see jQuery coders like to encapsulate code in autonomous functions, but I haven't read anything about why, and I'm not clear
on why. The benefit would be that locally declared variables aren't externally visible? That is, wouldn't the following code
perform as well?
var privatedata = 42;
$.fn.mypluginmethod = function() {};
$.myplugin = {
publicmethod1: function() {},
publicmethod2: function() {}
};
2 - The documentation describes the $.myplugin.publicmethod1 as being a technique for coding "private" functions. So wouldn't it be
more intuitive to write:
$.myplugin = {
privateMethod1: function() {},
privateMethod2: function() {}
};
And on a related note, if we like documentation with public/private in the names to improve the clarity, why isn't
$.fn.mypluginmethod (in 1 above) named $.fn.myPublicMethod?
Good questions or complete idiot? Only the responses will tell. ;-)
Sam
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/