剖析 mootools
我遇到了一个问题并需要解决该问题,需要在 mootools
中内置功能。所以我开始剖析它。 有一个我感兴趣的功能 IframeShim.destroy
现在就像这样
destroy: function(){
if (this.shim) this.shim.destroy();
return this;
}
我无法理解什么是shim
。 我特别想理解的是 Request.JSONP.cancel
它的代码是这样的
cancel: function(){
if (this.running) this.clear().fireEvent('cancel');
return this;
}
,现在这个取消调用clear
,其代码现在是这样的
clear: function(){
this.running = false;
if (this.script){
this.script.destroy();
this.script = null;
}
return this;
}
,在这个clear函数中我可以看到destroy()
,它将我带到shim(参见顶部的代码)并且我被卡住了。 所有这些功能都在 mootools-more.js
帮助?
如果有人可以提供 Request.JSONP.cancel
的纯 JavaScript 实现,那就太好了 它有 JQuery
替代品吗?
i had a problem and solving which required a functionality built in mootools
. so i began dissecting it.
there a function a am interested inIframeShim.destroy
its like this
destroy: function(){
if (this.shim) this.shim.destroy();
return this;
}
now what i cant understand in this what is shim
.
Paricularly what i am trying to understand isRequest.JSONP.cancel
its code is like this
cancel: function(){
if (this.running) this.clear().fireEvent('cancel');
return this;
}
now this cancel calls clear
whose code is like this
clear: function(){
this.running = false;
if (this.script){
this.script.destroy();
this.script = null;
}
return this;
}
now in this clear function i can see destroy()
which takes me to shim
(see code at the top) and i m stuck.
All these functions are in mootools-more.js
Help?
it would be great if somebody could provide a plain javascript implementation of Request.JSONP.cancel
Does it have a JQuery
alternative?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Request.JSONP.clear
方法调用的 destroy 不是IframeShim.destory
,它是 mootools 核心的一部分。来源如下:Element.dispose
所做的就是调用本机 jasvascript DOM 方法 Node.removeChild 从 DOM 中删除一个元素。因此,JSONP.cancel 所做的就是查看是否通过 Request.JSONP.cancel 添加了脚本 DOM 节点。如果是,它会通过removeChild 从 DOM 中删除脚本元素。
重要的是它将
running
标志设置为 false。如果您查看Request.JSONP.success
,它在调用回调函数之前所做的第一件事是检查running
标志是否设置为 false,如果是,它立即返回。这有效地“取消”了执行。如果您的意思是它是否取消 HTTP 请求,答案是否定的,它不会。
The destroy that is being called by the
Request.JSONP.clear
method isn'tIframeShim.destory
, it's part of the mootools core. Here's the source:All that
Element.dispose
does is call the native jasvascript DOM method Node.removeChild which deletes an element from the DOM.So all JSONP.cancel is doing is seeing if a script DOM node was added via
Request.JSONP.cancel
. If it was, it removes the script element from from the DOM via removeChild.The important thing is that it set the
running
flag to false. If you look atRequest.JSONP.success
, the first thing it does before calling your callback function is check if therunning
flag is set to false, and if it is, it returns immediately. This effectively "cancels" the execution.If you meant does it cancel the HTTP request, the answer is no, it does not.