在没有浏览器的情况下执行 JavaScript? [英] Executing JavaScript without a browser?

查看:54
本文介绍了在没有浏览器的情况下执行 JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究没有浏览器的 Javascript 编程.我想从 Linux 或 Mac OS X 命令行运行脚本,就像我们运行任何其他脚本语言(ruby、php、perl、python...)

I am looking into Javascript programming without a browser. I want to run scripts from the Linux or Mac OS X command line, much like we run any other scripting language (ruby, php, perl, python...)

$ javascript my_javascript_code.js

我研究了蜘蛛猴 (Mozilla) 和 v8 (Google),但它们似乎都被嵌入了.

I looked into spider monkey (Mozilla) and v8 (Google), but both of these appear to be embedded.

是否有人使用 Javascript 作为脚本语言从命令行执行?

Is anyone using Javascript as a scripting language to be executed from the command line?

如果有人好奇我为什么要研究这个,我一直在探索 node.js.node.js 的性能让我怀疑 javascript 是否可能是处理大数据的可行脚本语言.

If anyone is curious why I am looking into this, I've been poking around node.js. The performance of node.js makes me wonder if javascript may be a viable scripting language for processing large data.

推荐答案

我发现了这个 相关问题 关于这个话题,但如果你想要直接链接,这里有:

I found this related question on the topic, but if you want direct links, here they are:

  • 您可以像其他人指出的那样安装 Rhino.这篇文章 展示了一种启动和运行它的简单方法,以及如何为命令添加别名以轻松调用它
  • 如果您使用的是 Mac,则可以使用 JavaScriptCore,它会调用 WebKit 的 JavaScript 引擎.这是一篇关于它的帖子
  • 您也可以使用 Chome/Google 的 V8 解释器.这里是说明
  • 作为 OSA 的 JavaScript 很有趣,因为它让您 (AFAIK) 与可编写脚本的 OS X 应用程序交互,就像您在 AppleScript 中一样(没有糟糕的语法)
  • You can install Rhino as others have pointed out. This post shows an easy way to get it up and running and how to alias a command to invoke it easily
  • If you're on a Mac, you can use JavaScriptCore, which invokes WebKit's JavaScript engine. Here's a post on it
  • You can use Chome/Google's V8 interpreter as well. Here are instructions
  • The JavaScript as OSA is interesting because it lets you (AFAIK) interact with scriptable OS X apps as though you were in AppleScript (without the terrible syntax)

我很惊讶 node.js 没有自带 shell,但我猜它真的更像是一个基于 epoll/选择器的回调/面向事件的 web 服务器,所以它可能不需要完整的 JS 功能集,但我不太熟悉它的内部运作.

I'm surprised node.js doesn't come with a shell, but I guess it's really more like an epoll/selector-based callback/event-oriented webserver, so perhaps it doesn't need the full JS feature set, but I'm not too familiar with its inner workings.

由于您似乎对 node.js 感兴趣并且因为它基于 V8,所以最好按照有关设置 V8 环境的说明进行操作,以便您可以为 JavaScript 编程提供一致的基础(我希望 JSC 和V8 基本相同,但我不确定).

Since you seem interested in node.js and since it's based on V8, it might be best to follow those instructions on getting a V8 environment set up so you can have a consistent basis for your JavaScript programming (I should hope JSC and V8 are mostly the same, but I'm not sure).

这篇关于在没有浏览器的情况下执行 JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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