dojo中的this.own()
最近在看以前的項(xiàng)目中代碼的時(shí)候突然在構(gòu)造函數(shù)中發(fā)現(xiàn)了一個(gè)很有意思的片段this.own();不是很明白這是干什么的(因?yàn)槟莻€(gè)部分不是我寫的);所以果斷搜索,在Stack Overflow找到了很詳細(xì)的解釋:own函數(shù)是定義在dijit/Destroyable模型中的,這個(gè)模型是dijit/_WidgetBase的父類(姑且按照OOP的方式來(lái)),因此絕大多數(shù)的widget都實(shí)現(xiàn)了這個(gè)類。
再來(lái)看看官網(wǎng)API怎么說(shuō)的:
Call this.own(...) on list of handles (returned from dojo/aspect, dojo/on, dojo/Stateful::watch, or any class (including widgets) with a destroyRecursive() or destroy() method. Then call destroy() later to destroy this instance and release the resources.
意思就是實(shí)現(xiàn)了dijit/Destroyable類的對(duì)象在銷毀的時(shí)候使用了this.own()控制事件的綁定,那么這些實(shí)例會(huì)在銷毀的時(shí)候同時(shí)釋放這些綁定的內(nèi)存資源。
所以我們一般會(huì)在構(gòu)造函數(shù)中使用這個(gè)方法注冊(cè)事件。
原文:http://blog.csdn.net/sx341125/article/details/51771045
總結(jié)
以上是生活随笔為你收集整理的dojo中的this.own()的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: dojo中的dojo/dom-attr
- 下一篇: scrapy需要的xpath知识点