最后在Javascript中评估表达式 [英] Last evaluated expression in Javascript

查看:77
本文介绍了最后在Javascript中评估表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Javascript中获取上次评估表达式的结果?例如:

Is it possible in Javascript to get the result of the last evaluated expression? For example:

var a = 3;
var b = 5;
a * b;
console.log(lastEvaluatedExpression); // should print 15

所以它会像eval()那样返回最后一次计算的表达式,但我不能使用eval()。

So it would be something like eval() where it returns the last evaluated expression, but I cannot use eval().

推荐答案

最后评估表达式的结果没有标准的,具体化的概念在JavaScript中。实际上没有太多的语言确实有这样的东西。各种JavaScript REPL可以提供这些行的一些功能,但这些特定于那些REPL。没有一般的JavaScript方式。

There is no standard, reified concept of "the result of the last evaluated expression" in JavaScript. There are actually not too many languages that do have such a thing. Various JavaScript REPLs may provide some facility along these lines, but that's specific to those REPLs. Therei s no general "JavaScript" way.

这篇关于最后在Javascript中评估表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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