gpt4 book ai didi

javascript - 是否可以在 JavaScript 中推出您自己的 'function' 构造或 'eval' 方法?

转载 作者:行者123 更新时间:2023-11-28 14:00:54 24 4
gpt4 key购买 nike

是否有可能在纯 JavaScript 中重新实现“function”或“eval”?例如。假设我希望能够编写以下内容:

// note that I don't want to have to put code in a string here
var x = func() { var something = "nothing"; return something; }

var hiString = 'hi'  // note that it of course needs to be able to access the current context
evaluatize("function hi(){ alert(hiString); } hi();")

这些事情在 JavaScript 中可能实现吗?

最佳答案

你可以用 JavaScript 编写一个 JavaScript 解释器,比如 Narcissus .

关于javascript - 是否可以在 JavaScript 中推出您自己的 'function' 构造或 'eval' 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5206433/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com