获取当前范围内的所有已定义变量 [英] get all defined variables in current scope

查看:89
本文介绍了获取当前范围内的所有已定义变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在解析一个网站,其中包含的内容如

I'm parsing a website which contains stuff like

hmapId[7]='42500000000626135';
hmapStartInterv[7]='750';
hmapEndInterv[7]='846';
hmapUrlInterv[7]='some url';
hmapNameInterv[7]="some name"
hmapRoleInterv[7]='some role';

我的计划是将其写入 .js 文件并使用节点js执行它。之后我想要一些代码行给我以前定义的所有变量作为JSON来使用其他程序中的数据。最好的方法是什么?

My plan is to write that into a .js file and execute it with node js. After that I want to have some lines of code giving me all variables defined before as JSON to use the data in some other program. What's the best way to do this?

谢谢

推荐答案

当前范围,不可能(AFAIK),对于全局范围,您在node.js中有全局对象(窗口在导航器嵌入式js引擎中,它获取全局变量属性:

For the current scope, it's not possible (AFAIK), for the global scope you have the globalobject in node.js (window in navigator embedded js engines), which get the global variables properties:

// on global scope, with x not defined as a "var"
x=25
console.info(global['x']===x) // --> writes down 'true'

这篇关于获取当前范围内的所有已定义变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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