Access local variable from outside the function

情到浓时终转凉″ 提交于 2020-01-25 05:21:05

问题


I'm using TopUp to make a simple slideshow. Unfortunately they don't expose the image index.

Is there a way I can access the local variable "index" without having to modify the original script?

TopUp = (function() {
 var index = null;
    ...
}

回答1:


Without modifying the original script, you can't.

But if you just want to be able to read the value of index, the modification could be really simple, by adding a little function in the objet returned :

getIndex : function() {
  return index;
},



回答2:


There's no way to get that variable out. Looking at the (somewhat scary) source, It doesn't look like the "ondisplay" callback is passed anything useful, but it's not really clear (and the documentation doesn't mention the parameters at all).



来源:https://stackoverflow.com/questions/3770323/access-local-variable-from-outside-the-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!