如何评估全球范围 [英] how to eval in the global scope

查看:88
本文介绍了如何评估全球范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我想在一个函数上评估一些javascript代码。和我的代码包含

一些变量和函数定义。


我的问题是代码在函数范围内评估而不是全局

范围和定义在全球范围内不可用。

hi guys,

I want to eval some javascript code at a function. and my code contains
some variable and function definitions.

my problem is that the code is evaluated in function scope not global
scope and definations are not available in the global scope.

推荐答案

a。******* @ gmail.com 在2005年10月26日晚上11:07发表以下内容:
a.*******@gmail.com said the following on 10/26/2005 11:07 PM:
hi guys ,

我想在函数中评估一些javascript代码。我的代码包含一些变量和函数定义。


为什么你认为你需要评估?

我的问题是代码是在功能范围内评估而不是全局范围和定义不是可在全球范围内使用。
hi guys,

I want to eval some javascript code at a function. and my code contains
some variable and function definitions.
Why do you think you need eval?
my problem is that the code is evaluated in function scope not global
scope and definations are not available in the global scope.




然后将它们全局化。


-

Randy

comp.lang.javascript常见问题 - http://jibbering.com / faq &新闻组每周



Then make them global in scope.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly


我使用XMLHTTPRequest在运行时加载了一些js代码。

但我无法在全局范围内运行它。
<除了eval之外还有其他方法吗?

I load some js code on runtime using XMLHTTPRequest.
but I cant run it on the global scope.

Is there any more ways except eval?


Farhadi在2005年10月26日下午11:31说: br />

请引用您要回复的内容。


如果您想通过groups.google.com发布后续内容,请不要使用

回复链接在文章的底部。点击显示选项在

文章的顶部,然后点击回复。在

文章标题的底部。
Farhadi said the following on 10/26/2005 11:31 PM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don''t use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
我使用XMLHTTPRequest在运行时加载一些js代码。
但是我无法在全局运行它范围。
除了eval还有其他方法吗?
I load some js code on runtime using XMLHTTPRequest.
but I cant run it on the global scope.
Is there any more ways except eval?




实际上取决于代码本身。


让代码生成的方式是它可以附加在脚本中,包含在函数中的
块,然后调用该函数。但是那个

取决于代码及它应该做什么。


也可能有比XMLHTTPRequest更好的方法。
< br $> b $ b -

兰迪

comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组周刊



That depends on the code itself actually.

Have the code generated in a manner that it can be appended in a script
block, wrapped in a function, and then the function called. But that
depends on the code and what it is supposed to do.

There also may be a better way than an XMLHTTPRequest.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly


这篇关于如何评估全球范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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