码迷,mamicode.com
首页 > 其他好文 > 详细

eval-Evaluation

时间:2018-01-21 00:13:34      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:blog   ref   com   func   normal   task   ast   mod   rip   

eval is a function which evaluates a string as though it were an expression and returns a result; in others, it executes multiple lines of code as though they had been included instead of the line including the eval.

 

JavaScript[edit]

In JavaScripteval is something of a hybrid between an expression evaluator and a statement executor. It returns the result of the last expression evaluated.

Example as an expression evaluator:

foo = 2;
alert(eval(‘foo + 2‘));

Example as a statement executor:

foo = 2;
eval(‘foo = foo + 2;alert(foo);‘);

One use of JavaScript‘s eval is to parse JSON text, perhaps as part of an Ajax framework. However, modern browsers provide JSON.parse as a more secure alternative for this task.

https://en.wikipedia.org/wiki/Eval

 

 Implementation

In interpreted languageseval is almost always implemented with the same interpreter as normal code. In compiled languages, the same compiler used to compile programs may be embedded in programs using the eval function; separate interpreters are sometimes used, though this results in code duplication.

 

http://dictionary.sensagent.com/Eval/en-en/

eval-Evaluation

标签:blog   ref   com   func   normal   task   ast   mod   rip   

原文地址:https://www.cnblogs.com/feng9exe/p/8322159.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!