从函数外部访问局部变量 [英] Access local variable from outside the function

查看:52
本文介绍了从函数外部访问局部变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 TopUp 制作一个简单的幻灯片.不幸的是,他们没有公开图像索引.

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

有没有办法不用修改原脚本就可以访问局部变量index"?

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

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

推荐答案

不修改原脚本是不行的.

Without modifying the original script, you can't.

但是如果你只是想能够读取index的值,修改可以很简单,通过在返回的对象中添加一个小函数:

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;
},

这篇关于从函数外部访问局部变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆