Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Why wouldn't I just do:

    $.fn.misbehave = function () { alert('Oh behave!');}
    $('.bad-behavior').misbehave();
?

What is gain by adding an extra "object-oriented" wrapper around standard jquery functionality?



You're missing the point by miles, buddy. When you find some time, go beyond the simplest example.


I think the idea is to select multiple objects, assign them whatever behaviors you wish (if they exist) and execute those behaviors.

Even the simple example: #("#foo").missbehave is quite bad:

missbehave has to be defined as a jQuery global behavior on all objects, not something that is specific to every single dom element to which it was assigned:

$("#foo,#bar,#baz").behavior("missbehave") would mean that each of the 3 have potentially 3 different behaviors for missbehave in the same scheme of things, some might not even have those behaviors.

Think more along the lines of the state of a page:

You set a state, which configures behaviors. Execute the behaviors.

Change a state, change behaviors, execute them again.

Makes state management much easier. God I am wishing I had this about 3 weeks ago when I started my current project :)




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: