Go to Google Groups Home    Low Pro
Re: Prototype + lowpro vs. JQuery

Dan Webb <d...@danwebb.net>

On 1/26/08, Dan Webb <d...@danwebb.net> wrote:

> I'll see what I can put together.

We'll I've made a start and I must stay it works really nicely with jQuery.

http://svn.danwebb.net/external/lowpro-jq/trunk

Warning:  I've literally just bashed this out so its not ready for
usage but you can get an idea of how it goes together by looking at:

http://svn.danwebb.net/external/lowpro-jq/trunk/test/test.html

But the rundown is...

Create a behavior as a class:

Testy = $.klass({
  initialize: function(arg) {
    alert('ive just been attached with the arg ' + arg);
  },
  onclick: function() {
    alert('ive been clicked');
  }

});

Btw, $.klass is a full port of the Prototype Class.create stuff so you
get that as a bonus and can use all the inheritance stuff in the same
way.

Then attach it on ready in the jQuery way:

jQuery(function($) {
  $('p').attach(Testy, 'My arg');

});

And that's it.  Works the same for this point on.

Another little bonus is that if you are running livequery it does some
magic and automagically attaches new instances of the behaviour
whenever the DOM is changed so for the above example if you
$(document.body).append('<p>Another para</p>') then it gets its own
behavior instance as well.

So, I think it needs some more bashing (and some unit tests) and I
think it would be good to ship with some behaviors like normal Low Pro
does.  Probably Remote and Observed...

What do ya'll think?  After sitting and coding it Im actually really
pleased with how it turned out.  It's much simpler than the Prototype
implementation and fits jquery's style a lot more.  I might defect :)

Cheers,

Dan

--
Dan Webb
http://www.danwebb.net

aim: danwrong123
skype: danwrong