Sunday, December 14, 2008

Using Prototype with YUI

I have been using prototype.js with YUI for quite some time now for one simple reason. I LOVE classes. Prototype makes it easy to declare javascript classes, and use them wisely with YUI.

1) You can make easy wrapper classes around YUI classes :

var MyDataTable = Class.create(YAHOO.widgts.DataTable, { ... });

In this case you could set some defaults up for creating a DataTable the same way across your site.



2) $() is always helpful, but be mindful of my previous posts about performance. I think this function is useful in conjunction with YUI and YAHOO.util.Get is less readable (although you could still set $ to this function)

Also, consider $A() and $H() when passing variables around YUI constructors, or using .each()

3) In reverse, you could setup YAHOO namespaces, and then setup a nice structure for your prototype built classes, then use YUI loader or get chains to load them into your pages dynamically.

Loader is very powerful in may ways, don't underestimate it!

Any specific questions, Please post a comment :)

3)