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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Signs of a poorly written jQuery plugin

60 点作者 jimsteinhart将近 15 年前

5 条评论

NathanKP将近 15 年前
This article helped me a lot. I had always thought that it had to be written as:<p>$(this).each(...)<p>Knowing that I can use:<p>this.each()<p>will allow me to simplify things a bit.
评论 #1401613 未加载
评论 #1402682 未加载
评论 #1401477 未加载
naz将近 15 年前
His second point, "Double jQuery" is because of inconstancy in jQuery itself. For all event callbacks 'this' is the relevant DOM node, but for plugin functions 'this' is a jQuery object. It is understandable that a plugin author would assume that it is a DOM node and since calling $(this) would just return itself they have no way of knowing. I wouldn't say it reflects on the plugin author at all.
adamesque将近 15 年前
It's important to keep in mind that these are literally what the title makes them out to be: simple signposts that indicate poor code might lie within.<p>I probably wouldn't immediately toss out a plugin that exhibited one or more of these signs, but I <i>would</i> take it as a sign that I ought to do a slightly more thorough skimming of the code before using.<p>It's a shame that the jQuery plugin directory doesn't make separating the good from the bad much easier.
dhimes将近 15 年前
For the inline return:<p><pre><code> return $(this).each(fn); </code></pre> I'm actually surprised that the JS engines don't do this kind of optimization automatically.
评论 #1401748 未加载
评论 #1401921 未加载
apphacker将近 15 年前
#1. I hate the "this" keyword abuse in jQuery, this article demonstrates it clearly. #2. Some minor code style issues do not make a bad plugin.
评论 #1402975 未加载