Coincidence has it that there is even more server-side Javascript news right now: Jaxer
It is basically Mozilla running behind Apache on the server-side, extended with the server-side functionality you would expect, like reading/writing files, db access and other external communication. But since the server-side runs inside a full fledged browser environment, with not only the DOM but CSS and all the client-side js functionality, including XMLHTTP requests and the whole bit, you can really work on both sides with less mental switching.
Take a look at the example John Resig mentions :
<html> <head> <script src="http://code.jquery.com/jquery.js" runat="both"></script> <script> jQuery(function($){ $("form").submit(function(){ save( $("textarea").val() ); return false; }); }); </script> <script runat="server"> function save( text ){ Jaxer.File.write("tmp.txt", text); } save.proxy = true; function load(){ $("textarea").val( Jaxer.File.exists("tmp.txt") ? Jaxer.File.read("tmp.txt") : ""); } </script> </head> <body onserverload="load()"> <form action="" method="post"> <textarea></textarea> <input type="submit"/> </form> </body> </html>
Maybe sometimes it really helps to see both the client-side and server-sider code together like this, without the need to switch between separate files for views and controls. That's something to keep in mind for Jhino. With the older versions of Openmocha you always had the server-side and client-side code together on one page when using the web-based editor. With Jhino we currently lost that. So, this is one good argument to bring back a gui editor where one can see all the properties and behaviors of a Mocha object at a glance.
I'm not sure how often it will really make sense to run the code on both the client and server side. I hope we will come up with some interesting use cases for this, because the idea is intriguing!
23.1.2008, 13:07