jQuery UI 1.8.1 小部件的销毁函数中默认销毁的位置

发布于 2024-08-30 07:24:54 字数 768 浏览 6 评论 0 原文

好吧,我在编写自己的 jQuery UI 小部件插件时遇到了一点困惑。问题出在 destroy 函数上。在文档中,它说先放置默认的销毁,然后在其后写入该小部件特有的其他内容。

$.Widget.prototype.destroy.apply(this, arguments); // default destroy
// now do other stuff particular to this widget

请参阅 http://jqueryui.com/docs/Developer_Guide

但是在他们的示例脚本中(那些是实际的jQuery Ui 发布的代码的 pluings 是相反的,

$.Widget.prototype.destroy.apply(this, arguments);

请参阅 http://dev.jqueryui.com/browser/trunk/ui/jquery.ui.progressbar.js (以及所有其他内置小部件)

所以这是目前的widget的编写方式,还是Developer_Guide中代码注释中的解释?

Ok, I'm having a slight bit of confusion writing my own jQuery UI widget plugins. The problem lies in the destroy function. In the docs, it says to put the default destroy first then write other things particular to the widget after it.

$.Widget.prototype.destroy.apply(this, arguments); // default destroy
// now do other stuff particular to this widget

See http://jqueryui.com/docs/Developer_Guide

However in their example scripts (those being the actual pluings for jQuery Ui released code, does it the opposite. The

$.Widget.prototype.destroy.apply(this, arguments);

is at the end of the function. See http://dev.jqueryui.com/browser/trunk/ui/jquery.ui.progressbar.js (and all of the other built in widgets as well)

So which is it? The way the current widgets are written, or by the explanation in the code comment in the Developer_Guide?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你是我的挚爱i 2024-09-06 07:24:54

我个人会把它放在最后,以防发生任何疯狂的事情,但要确保你创建的任何东西都被销毁,然后让基本方法完成它们的工作。从实用的角度来看?

没关系

这只是一个品味问题,即使在您链接的两个示例中,编写它们的开发人员的品味也有所不同(或随着时间的推移而改变)......这不是一个足够大的问题以使文档保持一致。

免责声明:此处发表意见!
通常在这种情况下,我认为遵循代码的约定而不是文档会更安全。您正在浏览器中主动运行代码,通过了 jQuery 单元测试,正在运行......而不是可能准确或过时的文档。我知道我对此感到内疚,而且我并不孤单......我不经常更新文档,至少不像我重构/改进代码那样频繁:)

I would personally put it at the end, in case anything crazy happens, but make sure anything you've created gets destroyed, then let the base methods do their work. From a practical standpoint?

It doesn't matter

It's just a matter of taste, and even in the 2 examples you linked, the taste of the developers writing them differed (or changed over time)...not a big enough issue for the documentation to be consistent.

Disclaimer: Opinion here!
Usually in cases like this, I think it's safer to stay with the convention of the code instead of the documentation. You're actively running the code in your browser, it's passing the jQuery unit tests, it's what's running...not the documentation which may or may not be accurate or outdated. I know I'm guilty of this, and that I'm not alone...I don't update the documentation all that often, not near as often as I refactor/improve the code at least :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文