views:

188

answers:

4

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?

+8  A: 

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.

Pointy
Thanks. I probably wasn't clear. I already read about server-side scripting and node.js. I was thinking more about general purpose usage on the desktop -- shell scripting, desktop apps, etc.
Kawili-wili
Well, there's no reason you can't run node.js or any other out-of-the-browser Javascript runtime on your desktop, and just like on the server it has complete access to your filesystem, network, and anything else. It's the **browser environment specifically** that imposes restrictions.
Pointy
Thanks again. I misunderstood the use of node.js. I was thinking you had to first spin up a local server before you could use node.js. I just tried and was able to write to the file system directly. This is another great answer.
Kawili-wili
+1  A: 

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

klez
+4  A: 

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.

l33tnerd
Great answer, thanks. I did not know about JSLibs. The forums seem active, but it hasn't had a release since Dec 2009 (dev release). Feature complete? :-)
Kawili-wili
Yeah, it looks a little abandoned...but hey, if you really wanted JavaScript on the desktop, you could embed it in Python with PyV8 or otherwise make your own JSLibs.
l33tnerd
Very good answer. In addition js is being used as a common language to compile into native mobile apps. For example phonegap and grapple mobile
Joe
+1  A: 

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.

mfollett