John Napiorkowski schrieb: > Two things I'd really like are a good system for > creating classes with clear inheritance and support > for java-style interfaces. The second would be > support for namespaces and a way to include modules as > needed. > While I haven't build "really really big" applications (whatever that may be) with jQuery, I build several small and maybe one middle sized. And so far my experience is that jQuery's plugin model is all I need. The plugin describes the interface I need to know about. It has a default setup with at most two options to set, and can be configured to a certain extend via other options.
The plugin authoring guide documents at least parts of writing proper plugins: http://docs.jquery.com/Plugins/Authoring One thing that I often experienced as rather ugly is jQuery's use of Function.apply: Every jQuery method has "this" referring to the current jQuery object, which is great and just what I need. But all event handlers have "this" referring to the event firing element, which is ugly, because I loose the context of my own object inside event handlers. Workarounds must use closures, referring to the original object saved in a variable. I figured that the closure pattern could be reduced and then delegated. Because the above is quite abstract I'd like to provide a concrete example. Take a look at this file: http://jquery.com/dev/svn/branches/joern-dev/fuzz/validation/js/validate.js?format=txt Scroll to the definition of the plugin ( $.fn.validate = function(options) { Now take a look at the submit handler: // validate the form on submit this.submit(function(event) { if(v.settings.debug) { // prevent form submit to be able to see console output event.preventDefault(); } return v.validateForm(); }); As you can see, instead of using the validateForm method of my validator object as the event handler, I'm using an anonymous function that delegates to the object's method, keeping the object context intact. The object itself is referred to via a closure from inside the event handler, because "this" refers to the form instead of my validator object. Let me know if that helps you and if this should be added to the plugin authoring guide. -- Jörn Zaefferer http://bassistance.de _______________________________________________ jQuery mailing list [email protected] http://jquery.com/discuss/
