4 ms·
Some things to keep in mind: -Once you apply a behavior to an element, there is no way to remove it -There is no way to access the behavior by type, so if you
by warfangle 17y ago
Some things to keep in mind:
-Once you apply a behavior to an element, there is no way to remove it
-There is no way to access the behavior by type, so if you add two different behaviors to an element, you can't (or at least, from what I can glean from the documentation) access one of the specific behaviors. This could get problematic if you have two different behaviors with identically named properties.
Just like events, being able to apply and remove things like this is very helpful.
- rodp 17y agoActually you can remove it. For example: $('.some-behavior').each(function () { this.behavior = null; }); I'll make sure to add a prettier way of doing this in the next release. As for the multiple behaviors issue - it's a philosophical question: Should it be possible for one element to be an instance of more than one behavior or should we let the developer "mix" several behaviors into one, which is simple and not really that hard to do? I chose the latter.
- IgorPartola 17y agoI think in most cases you can get away with using a single behavior for a single control that encapsulates all of the control's logic. I suppose if you only have one: removing a behavior is as simple as just re-creating the element. A bit clunky, so an API for this would be nice, but it works.