javascript dojo 中 this.own() 方法的使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15363019/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use of this.own() method in dojo
提问by Lucian Depold
i would like to know the intention of the "this.own()" method in dojo widgets. This method is mentioned in the Dojo Api 1.8 Documentation, for example under diijit/form/button. I did not find anything that made sense to me on google. That is how the method is mentioned:
我想知道 dojo 小部件中“this.own()”方法的意图。Dojo Api 1.8 文档中提到了这个方法,例如在 diijit/form/button 下。我在谷歌上没有找到任何对我有意义的东西。这就是方法被提到的方式:
connect(obj, event, method)
Deprecated, will be removed in 2.0, use this.own(on(...)) or this.own(aspect.after(...)) instead.
连接(对象,事件,方法)
不推荐使用,将在 2.0 中删除,使用 this.own(on(...)) 或 this.own(aspect.after(...)) 代替。
回答by Craig Swing
The own
function is defined in dijit/Destroyable
, which is a base of dijit/_WidgetBase
and thus most widgets.
该own
函数在 中定义dijit/Destroyable
,它是dijit/_WidgetBase
大多数小部件的基础。
dijit/Destroyable is used to track handles of an instance, and then destroy them when the instance is destroyed. The application must call destroy() on the instance in order to release the handles
dijit/Destroyable 用于跟踪实例的句柄,然后在实例销毁时销毁它们。应用程序必须在实例上调用 destroy() 以释放句柄
http://dojotoolkit.org/reference-guide/1.8/dijit/Destroyable.html
http://dojotoolkit.org/reference-guide/1.8/dijit/Destroyable.html
http://dojotoolkit.org/reference-guide/1.8/dojo/Evented.html
http://dojotoolkit.org/reference-guide/1.8/dojo/Evented.html
回答by 0leg
The short answer is: most of the things that you define inside .own()
are getting correctly removed once the widget itself is destroyed. Using .own()
prevents memory leaks in your app.
简短的回答是:.own()
一旦小部件本身被销毁,您在内部定义的大部分内容都会被正确删除。使用.own()
可以防止应用程序中的内存泄漏。
回答by user100712
To remove a widget from a page, you can either call destroy or destroyRecursively on your widget.
When you do that, anything that you added using this.own ( dojo/on, dojo/aspect, dojo/topic, dojo/router, the creation of a related DOM node or widget, etc.) will be removed and/or unregistered automatically. This is implemented via the dijit/Destroyable interface.
要从页面中删除小部件,您可以在小部件上调用 destroy 或 destroyRecursively。
当您这样做时,您使用 this.own 添加的任何内容(dojo/on、dojo/aspect、dojo/topic、dojo/router、相关 DOM 节点或小部件的创建等)都将被删除和/或取消注册自动地。这是通过 dijit/Destroyable 接口实现的。