获取所有的Javascript变量? [英] Get all Javascript Variables?
本文介绍了获取所有的Javascript变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在此先感谢:)
编辑,问题第2部分:
如何获取这些变量?这是我的尝试:
这是我结束了,根据评论意见:
for(var name in this){
variables [name] = name;
variables [name] = this [name]
}
解决方案Flanagan的JavaScript - 权威指南在第653页给出了以下内容:
var variables =
for(var name in this)
variables + = name +\\\
;
Is there a way for javascript to detect all assigned variables? For example, if one js file creates a bunch of vars (globally scoped), can a subsequent file get all the vars without knowing what they're named and which might exist?
Thanks in advance :)
EDIT, Question Part 2:
How do I get the values of these variables? Here is what I have attempted:
This is what I ended up with, as per comment suggestions:
for (var name in this) {
variables[name] = name;
variables[name]=this[name]
}
解决方案
Flanagan's "JavaScript - The Definitive Guide" gives the following on page 653:
var variables = ""
for (var name in this)
variables += name + "\n";
这篇关于获取所有的Javascript变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文