Changelog

JavaScript Icon changelog.com

jquery.behavior: chunk up your jQuery into 'behaviors'

logged by @logbot 2009-12-21T16:46:31Z permalink #javascript

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!')

[Source on GitHub] [Homepage]

0:00 / 0:00