简体   繁体   中英

Javascript as a general purpose language?

In a weekend geek seminar I attended, several instructors extolled the virtues of Javascript. I've used Javascript to some extent, but their enthusiasm caused me to want to step a little closer.

I've learned bits-and-pieces about Rhino & SpiderMonkey. I know about server-side scripting & the restrictions placed on local file access (and the reasons why).

I wondered if Javascript would ever take it's place alongside perl and python as a general purpose language? Not b/c there is any lacking in the languages that exist, but simply for those skilled in its use to broaden the scope of their reach.

I'm not so interested in a prediction of the future as I am about the current possibilities, the barriers in the way, and what's on the near-term table that might make this more of a reality.

Are some of you perhaps using the language in such way now? Shell scripting, local apps, etc.?

If so, how are you working around the issues of local file access and other things, such as databases?

Server-side Javascript doesn't have the restrictions on file access that client-side Javascript has.

Look at the node.js project for some inspiration.

I haven't used it, but JSLibs - http://code.google.com/p/jslibs/ - aims to be a way to get javascript running as a general purpose scripting language.

"Jslibs is a standalone JavaScript development runtime environment for using JavaScript as a general-purpose scripting language."

Of course, with new developments like Google's Web Apps, web apps, written in JavaScript, start to become more like desktop apps, written in Python and other languages (if that's what you're after). For instance, Chrome 7(?)+ has an about:labs feature named Background WebApps:

"Allows installed web apps to run in the background at system startup and continue running after all windows are closed."

And new features like the HTML5 File API also allow closer integration with the desktop, allowing you to do more from JavaScript in a web app than before. There are still restrictions on these features, and not all browsers implement them, but they allow you to do more with just JavaScript in a browser.

Google Chrome OS also does this - now all the applications are just web applications, built on HTML, JavaScript, etc. This is still in the future, however.

EDIT: I remembered some other ways to get JavaScript on the desktop.

QtWebkit - part of Qt - allows you to embed webkit in a Qt application, along with JavaScript.

Appcelerator Titanium ( http://www.appcelerator.com/ ) allows you to make desktop applications with HTML, CSS, JavaScript, Python, Ruby, and PHP, is cross-platform, is actively developed and used, and generally seems nice.

Adobe AIR ( http://www.adobe.com/products/air/ ) is similar to Titanium in its concepts.

All of these are ways to basically integrate web apps into the desktop.

You can use node.js for server side development. It is pretty neat. You can also use Rhino , both to integrate with Java or to have freeform scripts. Here is an example of a Rhino script that reads in a file.

At least in the circles that I follow it seems that JavaScript is becoming incredibly popular thanks to node.js. The fact that almost everyone has done some level of JS development appeals to people.

Firefox is partly written in Javascript (the GUI if I remember well). So yes, someone used it as a general purpose language.

有一个新的替代方案,在桌面上使用javascript -webkit带来(nodejs本机模块和模块系统+ node-webkit v8 C ++绑定功能+ GUI API)到chrome envirement

I do most of my general scripting these days using rhino. As a java dev, I find it gives me the best of both worlds. The flexibility of javascript, and the libs I'm familiar with when I need them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM