惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

博客园 - 一江秋水

oracle 数据库 web 开发 正则表达式 职业生涯【3】认真对待选择 职业生涯【2】选择行业、领导 职业生涯【1】选择职业 IE8正在连接(二级页面无法打开) Win7允许/禁用 PING命令 SQL2008 安装后启用 Sa 用户的方法 - 一江秋水 项目计划管理--(摘录) 如何收缩和删除SQL日志文件 IBatis—源码解析【DataAccess】 IBatis—源码解析【DataMapper】 Ibatis—源码解析【Common】 JavaScript调用WebServices sql server中的varchar和Nvarchar有什么区别 自动从起数据库服务 DataGridView显示行号 中国移动的短信息服务中心 - 一江秋水 - 博客园 Socket(同步与异步) C# 中用Socket实现判断网络是否断开的实例
JavaScript中Eval详解
一江秋水 · 2009-04-14 · via 博客园 - 一江秋水

eval可以将字符串生成语句执行,和SQL的exec()类似。 

eval的使用场合是什么呢?有时候我们预先不知道要执行什么语句,只有当条件和参数给时才知道执行什么语句,这时候eval就派上用场了。举个例子: 

我们要做一个(),功能是输入网页中两个个对象的名称,然后程序就将这两个对象的值联接起来输出。 

 output(a,b) 

var tmpa,tmpb; 
tmpa=all.a.; 
tmpb=all.b.; 
write(tmpa+tmpb); 

output('input1','input2'); 

这样你执行的时候就会提示错误“all.a不是对象”以及“all.b不是对象”。原来java把a和b当成对象名称了,怎样能让java把a里面的值作为对象名称呢?这时候就要用eval了,把代码改成这样: 

 output(a,b) 

var tmpa,tmpb; 
tmpa=eval("all."+a+"."); 
tmpb=eval("all."+b+"."); 
write(tmpa+tmpb); 

output('input1','input2'); 

这样java就会先取出a,b的值,然后和前面的all.以及后面的.组合运行,于是就可以 
顺利取出input1和input2的值,我们的目的达到了。