犀牛与蜘蛛猴
我注意到 ubuntu 10.04 删除了 Spidermonkey 软件包。犀牛看起来仍然在那里。 rhino 和 Spidermonkey 之间有什么区别(除了它们是用什么语言编写的)。他们为什么要移除蜘蛛猴?
I noticed ubuntu 10.04 removed the spidermonkey package. Rhino looks like it's still there though. What are the differences between rhino and spidermonkey (besides what language they're written in). And why did they remove spidermonkey?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
恐怕区别在于它们所用的语言或含义。人们使用 C/C++ 编写各种东西(例如 Firefox),而 Java 在应用程序服务器中最为流行。来自http://en.wikipedia.org/wiki/Rhino_%28JavaScript_engine%29:
这里有三个重要的部分。首先,没有 DOM(SpiderMonkey 也是如此)。其次,服务器端是预期用途。您应该能够在大型企业应用程序中使用 Rhino,以更加临时的方式实现自动化。最后,Javascript 成为一个类,就像 Java 类层次结构的其余部分一样,您可以与 Java 类交互(请参阅该页面上的代码示例)。
简而言之,您可以非常轻松地操作 POJO/基于 JPA 的对象/消息 Bean/任何您想要调用的“企业”Java 类,所有这些都可以在通过 Rhino 运行的 javascript 中进行。将此与 Jython 进行比较,在 Jython 中您可以使用 Python 语法和类与 Java 交互。如果你有一些 JavaScript/Python 高手在办公室里无所事事,这会很方便。
相比之下,SpiderMonkey 更像是 LUA。它是一种脚本语言。有什么区别?好吧,我怀疑你是否可以直接访问 printf 。您无法直接访问 C/C++ 类,而不是直接访问 Java 类。相反,您可以使用 C/C++ 来对该语言的额外功能进行编程。
简而言之,Rhino 允许 JS 与您的代码交互。 SpiderMonkey 更像是一个 DIY 编译器套件,其附加优势是已经构建了很多人都知道的标准语言,您只需向其中添加自定义即可。
I'm afraid the difference is the language they are written in, or what it means. People use C/C++ to write all manner of things (like Firefox) whereas Java is most prevalent in Application Servers. From http://en.wikipedia.org/wiki/Rhino_%28JavaScript_engine%29:
There are three important parts here. Firstly, there's no DOM (also true of SpiderMonkey). Secondly, server side is the intended usage. You're supposed to be able to use Rhino in your big enterprise-y application for automating stuff on a more ad-hoc basis. Finally, the Javascript becomes a class just like the rest of the Java class hierarchy and you can interact with Java classes (see the code sample on that page).
In short, you could quite easily manipulate your POJOs/JPA-based objects/Message Beans/whatever you want to call your "enterprise" Java class, all from within a javascript run through Rhino. Compare this to Jython, where you can use Python syntax and classes to interact with Java. Handy if you have some JavaScript/Python whizzes kicking around the office with nothing to do.
SpiderMonkey by contrast is more like LUA. It's a scripting language. What's the difference? Well, I doubt you get access to printf directly, for one. Rather than being able to access Java classes straight off, you don't get to access C/C++ classes straight off. Rather, you use C/C++ to program extra features of the language.
In short, Rhino allows JS to interact with your code. SpiderMonkey is more like a do-it-yourself compiler kit with the added advantage that a standard language a lot of people know has already been built and you just need to add your customisations to it.
由于我很难在 Ubuntu 上找到有关 JavaScript shell/解释器的基本示例,尤其是
rhino
- 我将在此处发布此内容...基本上,我对要安装什么以及安装什么感到有点困惑某种命令行来调用:)
首先,我发现 Bug # rhino (Ubuntu) 中的 705339:“Rhino shell 因 NullPointerException 崩溃” - 并意识到 OpenJDK 实际上安装了
rhino.jar
Java 存档。因此,如果你有这个,你可以立即在 bash 终端 shell 中执行以下操作:这对于基本的东西来说已经足够了......但是,如果您想使用 DOM
window
对象或setTimeout()
函数 - 本质上,这些是“浏览器特定的”实现”(对于setTimeout
,另请参阅 SO:7286178),没有浏览器的脚本引擎不会“知道”它们。然而,至少对于
rhino
来说,这是通过 Envjs “浏览器环境”来解决的库,其rhino
的最新版本 - 1.2 是 env.rhino.js(参见SO:6170676 用于rhino
中的setTimeout
)。所以我们可以做这样的事情:
...并且哎呀 - 它不起作用:)但是,这在 由于 getCurrentContext 错误,无法运行 1.2。 - Env.js | Google 网上论坛:
值得庆幸的是,在 Ubuntu 中我们可以直接执行以下操作,而不是从源代码构建:
... 因为 rhino filelist 指出,此软件包安装
js-1.7R2.jar
。该软件包还安装了一个脚本rhino
,它本质上是这些 Java 档案的 shell 包装器(请参阅less $(which rhino)
) - 因此我们可以方便地使用它输入java -jar ...
等:
但是,现在尝试将这些相同的行包含为脚本,我们将其称为
test.js
:并尝试在其上调用
rhino
:
哦天哪——又失败了,现在怎么办? :) 好吧,值得庆幸的是,即使这一点在 Envjs 指南 中也有所暗示(注意:请允许该页面使用 JavaScript,否则代码将几乎不可见) - 特别是:
对 - 所以最后,我们只需添加此优化设置,并且:
...最终它起作用了:) 编辑:使用
env.rhino.1.2.js
,您还可以使用console.log()
写入stdout。编辑:要运行rhino
Java调试器,请参阅使用less $(which rhino)
安装特定的.jar,然后调用java
直接(rhino 脚本使用一组不同的命令行开关,因此无法说服调用调试器):
如果您现在尝试使用
spidermonkey
运行相同的脚本(另请参阅 在Ubuntu 11.04上获取spidermonkey js的最佳方式?),你会得到:...也就是说,
spidermonkey
将无法与env.rhino.1.2.js
一起使用。好吧,希望这对某人有帮助,
干杯!
Since I have great difficulties finding basic examples about JavaScript shells/interpreters, especially
rhino
, on Ubuntu - I'll post this here...Basically, I was a bit confused on what to install, and what sort of command line to call :)
First of all, I found Bug #705339 in rhino (Ubuntu): “Rhino shell crashes with NullPointerException” - and realized that OpenJDK actually installs a
rhino.jar
Java archive. So if you have that, you can immediately do in the bash terminal shell:And this is all good enough for basic stuff... However, if you want to use DOM
window
object, orsetTimeout()
function - essentially, those are "browser specific implementations" (forsetTimeout
, see also SO:7286178), and a scripting engine without a browser wouldn't "know" about them.However, at least for
rhino
, that is remedied by the Envjs 'browser environment' library, whose Latest release - 1.2 forrhino
is env.rhino.js (see SO:6170676 forsetTimeout
inrhino
).So we can do something like this:
... and ooops - it doesn't work :) However, that is clarified in Can't run 1.2 due to getCurrentContext error. - Env.js | Google Groups:
Thankfully, instead of building from source, in Ubuntu we can directly do:
... since as the rhino filelist states, this package installs
js-1.7R2.jar
. The package also installs a scriptrhino
, which essentially is a shell wrapper for these Java archives (seeless $(which rhino)
) - so we can conveniently use that, instead of typingjava -jar ...
etc:However, now try including these same lines as a script, let's call it
test.js
:and try calling
rhino
on it:Oh dear - fails again, now what ? :) Well, thankfully, even this is somewhat hinted at in Envjs Guide (note: do allow javascript for that page, otherwise the code will be barely visible) - in particular:
Right - so finally, we simply add this optimization setting, and:
... finally it works :) EDIT: with
env.rhino.1.2.js
, you can also useconsole.log()
to write to stdout. EDIT: To run therhino
Java debugger, see usingless $(which rhino)
where are the particular .jars installed, and then calljava
directly (therhino
script uses a different set of command line switches, and so cannot be persuaded to call the debugger):If you try to run the same script now with
spidermonkey
(see also PPA instructions in Best way to get spidermonkey js on Ubuntu 11.04?), you will get:... that is,
spidermonkey
will not work withenv.rhino.1.2.js
.Well, hope this helps someone,
Cheers!
根据他们开发的语言,开发人员需要使用 Spidermonkey 显式处理内存。由于 rhino 是用 java 开发的,其中包括自动垃圾收集,并且从 Java 1.6 版本开始,JVM 的 [ Java 虚拟机 ] 已被调整为比 c 或 c++ 执行速度更快。
Based on the languages they have been developed, developer needs explicitly handle memory using spidermonkey. As rhino has been developed in java which includes automatic garbage collection and JVM's [ Java Virtual Machine ] have been tuned for faster execution than c or c++ from Java 1.6 Version.