jquery.behavior: chunk up your jQuery into 'behaviors'
If you’ve written more than a trivial amount of jQuery, you quickly wonder about the best way to organize your JavaScript. @rodpetrovic’s take is called jquery.behavior:
// 1. Create behavior:
function BadBehavior(element, config) {
this.misbehave = function () {
alert('Oh behave!');
}
}
// 2. Attach behavior:
$('.bad-behavior').behavior(BadBehavior);
// 3. Use behavior:
$('.bad-behavior').behavior('misbehave'); // alert('Oh behave!')
Discussion
Sign in or Join to comment or subscribe