TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

jQuery.Behavior: Simple jQuery library for boosting productivity

48 点作者 vuknje超过 15 年前

7 条评论

JoelSutherland超过 15 年前
Here is the jQuery way to do this:<p><a href="http://docs.jquery.com/Plugins/Authoring" rel="nofollow">http://docs.jquery.com/Plugins/Authoring</a><p>Plus Event Binding:<p><a href="http://blog.rebeccamurphey.com/2009/12/03/demystifying-custom-events-in-jquery/" rel="nofollow">http://blog.rebeccamurphey.com/2009/12/03/demystifying-custo...</a>
评论 #995089 未加载
rodp超过 15 年前
Thanks for the post.<p>I know the introduction is a bit long, sorry. I wrote it while I was hacking and I think I was even drinking some wine during that process, so... I'll write a shorter, clearer introduction soon, I promise.<p>The problems that occur when your JavaScript (jQuery) code starts piling up are nothing new. I've been finding ways to organize my code for ages.<p>The idea behind behaviors is simple really:<p>1. Encapsulate some type of functionality within a good old function. 2. "Attach" this function to some elements as their "behavior". 3. Methods and properties of all behaviors can be accessed from anywhere, which allows interaction.<p>It's a simple object-oriented philosophy and it's nothing new. I just think it would be nice to have a standard way of organizing huge piles of JavaScript without having to use some huge JS framework or moving too far away from the jQuery coding style.
bobbyi超过 15 年前
Why wouldn't I just do:<p><pre><code> $.fn.misbehave = function () { alert('Oh behave!');} $('.bad-behavior').misbehave();</code></pre> ?<p>What is gain by adding an extra "object-oriented" wrapper around standard jquery functionality?
评论 #994955 未加载
warfangle超过 15 年前
Some things to keep in mind:<p>-Once you apply a behavior to an element, there is no way to remove it<p>-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.<p>Just like events, being able to apply and remove things like this is very helpful.
评论 #994215 未加载
评论 #994220 未加载
IgorPartola超过 15 年前
I will give this a try next time I need to do something like this. This plugin can nicely encapsulate UI elements. Keep up the good work.
nkabbara超过 15 年前
How is this different than Dan Webb's lowpro?
arnorhs超过 15 年前
nice. I don't 100% understand it or how you would use it and why you would use it and not just write jquery code and structure it logically,... but then again I'm constantly finding my jquery code to slowly becoming big and using global variables and stuff to encapsulte objects' behavior... but unfortunately, I don't really understand this enough...