首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >到_destroy()还是销毁()?

到_destroy()还是销毁()?
EN

Stack Overflow用户
提问于 2013-04-08 18:14:46
回答 2查看 3K关注 0票数 2

对于要在_destroy UI Widget中实现哪个jQuery或destroy方法,我有点困惑。

在这个MSDN Widget引用中,它说要实现destroy(),但是在这个教程+引用中,它说要实现_destroy()

两个引用都指出,这些方法应该将元素返回到它的预小部件状态。所以我理解这个部分,但是为什么小部件工厂中有两个版本的这个方法呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-04-08 18:18:23

从jQuery UI中读取文档,而不是在MSDN上读取

http://wiki.jqueryui.com/w/page/12138135/Widget%20factory

代码语言:javascript
复制
// Use the destroy method to clean up any modifications your widget has made to the DOM
destroy: function() {
  // In jQuery UI 1.8, you must invoke the destroy method from the base widget
  $.Widget.prototype.destroy.call( this );
  // In jQuery UI 1.9 and above, you would define _destroy instead of destroy and not call the base method
}

});

票数 2
EN

Stack Overflow用户

发布于 2014-06-18 14:29:40

只是为了澄清(并基于):

在jQuery UI 1.8中,您的小部件应该如下所示:

代码语言:javascript
复制
$.widget( "demo.widget", {
    destroy: function() {
        // Invoke the base destroy method
        $.Widget.prototype.destroy.call( this );
        // Perform widget-specific cleanup
        ...
    }
});

在jQuery UI 1.9中,如下所示:

代码语言:javascript
复制
$.widget( "demo.widget", {
    _destroy: function() {
        // Perform widget-specific cleanup
        ...
    }
});

也就是说,在1.9中,您不应该定义(public) destroy方法;而是定义_destroy;并且在其中不需要调用基本调用析构函数。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15886043

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档