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

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

问题描述

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

  $ javascript my_javascript_code.js 

我看过蜘蛛猴)和v8(Google),但这两个似乎都是嵌入的。



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



如果有人好奇为什么我正在寻找这个,我一直在窥探 node.js 。 node.js的性能让我想知道javascript是否是一个可行的脚本语言来处理大数据。

解决方案

有关该主题的相关问题,但如果您想要直接链接,那么他们是: / p>


  • 您可以像其他人指出的那样安装Rhino。 这篇文章显示一个简单的方法来启动和运行,以及如何对命令进行别名调用

  • 如果您使用的是Mac,可以使用JavaScriptCore调用WebKit JavaScript引擎。 这里有一篇文章

  • 您可以使用Chome / Google的V8解释器。 这里有说明

  • JavaScript作为OSA很有趣,因为它让您(AFAIK)与可编写脚本的OS X应用程序交互,就像您在AppleScript中一样(没有可怕的语法)



node.js没有一个shell,但我想它更像是一个基于epoll /选择器的回调/面向事件的webserver,所以也许不需要完整的JS功能集,但我不是熟悉它的内部工作。



由于你看起来对node.js感兴趣,因为它基于V8,最好按照这些说明获得一个V8环境集因此你可以有一个一致的基础为你的JavaScript编程(我希望JSC和V8大部分是一样的,但我不知道)。


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

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

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

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:

  • 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)

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.

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天全站免登陆