当我将父方法包装在javascript中的私有函数中时如何调用方法
我不确定我的问题措辞是否正确,但无论如何......
我正在使用 iscroll 并将 iScroll init 调用包装在一个私有函数中以供稍后使用。这就是我所拥有的:
Namespace.iscroll = function () {
var myScroll;
myScroll = new iScroll('mainContent-wrap', {
hScrollbar: false
});
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', Namespace.iscroll, false);
};
我使用 Namespace.iscroll();
在我需要的任何页面上调用 iscroll
我的问题是,现在我想使用 myScroll.refresh();< 刷新 iScroll /code>,或使用 iScroll 文档中描述的
setTimeout
函数。
由于我将原始的 init 调用包装在私有函数中,如何在其上运行刷新和其他方法(如销毁)?
I'm not sure I worded my question correctly but anyhow...
I'm using iscroll and wrapped the iScroll init call in a private function for my use later. this is what I have:
Namespace.iscroll = function () {
var myScroll;
myScroll = new iScroll('mainContent-wrap', {
hScrollbar: false
});
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', Namespace.iscroll, false);
};
I call iscroll on any page I need by using Namespace.iscroll();
My question is, now I want to refresh iScroll using myScroll.refresh();
, or using the setTimeout
function as descriobed in the iScroll documentation.
Since I wrapped the original init call in a private function how to I run the refresh, and other methods (like destroy) on it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在运行
iscroll
函数后尝试访问myScroll
变量,答案是不能。到那时就消失了。您必须将其保存在其他地方,以便您可以访问它。一种想法是将其与iscroll
放在同一个对象上,如下所示:然后您可以像这样进行刷新:
关键是您将 myScroll 存储在某个持久且公共的位置,而不是临时的局部变数。
If you're trying to get access to the
myScroll
variable after theiscroll
function has been run, the answer is you can't. It's gone at that point. You will have to save it somewhere else so you can get to it. One idea is to put it on the same object asiscroll
like this:You can then do a refesh like this:
The key is that you store myScroll in some persistent and public location that isn't a temporary local variable.