I know I posted something earlier about plugin authoring, but this is
much more fitting. Please read on. I don't mean to sound arrogant in
any of this and would really like some constructive feedback on what
you guys think about this, how it compares to $.widget and other
methods that have been put up for consideration. This has been an
ongoing topic for awhile now.

It is designed to give jQuery an unlimited number of namespaces while
using 'this' in each one as you would in jQuery, but without
inheriting jQuery's methods.

http://code.google.com/p/jquery-plugin-dev/source/browse/trunk/jquery.namespace.js


Take the following example in context of jQuery UI:

$.fn.dialog = $.namespace(function() {
    // initialize the dialog window
});
$.fn.dialog.fn.open = function() {
    // open the dialog window
}

// would now allow
$('div').dialog().open();

// instead of
$('div').dialog('open');


A slightly more complicated example:

// will assign an empty function if one isn't passed
$.fn.namespace1 = $.namespace();
$.fn.namespace1.fn.namespace2 = $.namespace();
$.fn.namespace1.fn.namespace2.fn.namespace3 = $.namespace();
$.fn.namespace1.fn.namespace2.fn.namespace3.fn.getHtml = function() {
    return $(this).html();
}

// now this will work; not that you will need 3 namespaces...
alert($('div:first').namespace1().namespace2().namespace3().getHtml
());


Or even:

function test() {};
test.prototype.method1 = function() {};
test.prototype.method2 = function() {};

$.fn.test = $.namespace(test);

// and now you can extend it
$.extend($.fn.test.fn, {
    method3 : function() {},
    method4 : function() {}
});


I am not trying to push this into the core, but I haven't yet seen
anything that allowed this to be done with jQuery (I don't think
$.widget can do this) and is much more effective and extensible than
using something such as .dialog('open'). I think that this would be
worth considering; not because I wrote it, but because it really could
enable much more flexibility in jQuery. As jQuery grows, so will the
need for method organization, especially in jQuery UI.



On Aug 6, 7:44 am, Jörn Zaefferer <joern.zaeffe...@googlemail.com>
wrote:
> jQuery UI provides $.widget, and with some improvement on the way,
> should provide the benefits of prototypal inheritance without forcing
> the user to really bother with it. And it has been considered to move
> $.widget to jQuery core, as $.plugin.
>
> Jörn
>
>
>
> On Wed, Aug 5, 2009 at 4:24 PM, Már<mar.orlygs...@gmail.com> wrote:
>
> > So, would jQuery and jQuery plugin developmers benefit from having
> > some sort of (highly optimized of course ;) prototypal inheritance
> > methods built into the core library?
>
> > My vote: Yes.
>
> > What do you guys think?
>
> > --
> > Már
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to