One Standard: JavaScript Both Client and Server. Is it Possible today?

I am enamored by the idea that I could actually program the client and the server using the same language. I want to use Standard ECMA script on both the client and the server. Is this possible today in a safe way without going back to classic ASP

Here are my requirements:

1) Be able to create objects exactly the same way both (cut and paste) on both client and server.

2) Be able to use Lambda functions the same way both client and server.

3) Be able to use "eval" both client and server.

4) Retain dynamic typing in all of it's glory both client and server.

5) The ability to use the .NET framework (CLI) standard server-side.

What I don't require:

1) Uber-high performance (unless I have too, heck I'm already using asychronous elements, speed is obviously not my number one concern)

2) Static typing ( Nice option, but I don't have that requirement in an agile world.)

3) Class-based objects (that appears to be for static-typing dependents and people who want to make cheaper compilers.)

4) Non-standard JavaScript elements, (why would I willingly adict myself to anything that makes me a dependent )

5) Excuses about the eval statement (daisies in your lawn can be bad too but does that give cause to eliminate dasies from the planet Some people like them if carefully placed in other appropriate places, this is all I ask).

6) Cool new propriatary, non-standard interfaces. (I don't need any propriatary layers when JavaScript is so easy and free code is so common in this zone.)

JScript .NET is the best thing going server-side as far as I'm concerned. It talks to the ISO Standard Server environment (CLI). It's almost there out of the box. Is it possible to make JScript .NET language work just like the broswer(safely) If so, how



Answer this question

One Standard: JavaScript Both Client and Server. Is it Possible today?

  • csgary

    I would like to second these thoughts. As a test driven agile developer JavaScript makes these two practices feel natural rather than contrived as when I'm writing code in a typed language.

    Here are my requirements:

    1. A dynamic language so that I can create objects that fit my tests rather than spending many hours hammering out interface, stub, mock and delegate objects to fit into my test. This leads to complex multilayer code that can be wiped away with dynamics.

    2. Access to the .Net framework via a dynamic language. How easy would it be to test my code all the way down to the database command object if I could just dynamically create it using lambda functions

    3. The ability to write standard server and client code in the same language. Its coming and fighting it will alienate the developers who are sick of learning the next greatest version.

    4. I don’t need a bloated AJAX interface in Atlas. If you want to help me, provide light agile tested code that I can manipulate and extend.

    5. When you give code away for free give me the test harnesses as well. I will then be able to understand your code faster and as a bonus the examples are built in.

    The .Net framework is great but it is hard to be creative and at the same time simple with a typed language. Typed languages force me into abstractions that are only there because I need to have all code under test. JavaScript is so close can you pick it up and let it run on the server against the .Net framework


  • Garrett Serack

    I agree with these suggestions wholeheartedly.

    I still want to know the answer to my question as to whether there is a way to use the exact same language of JScript both client and server. The problem with the existing JScript .NET is that it is very different than the browser versions that are common in browsers.

    The browser version allows functions to be created as objects and allows prototyped objects to be extended with new methods without using extra syntax. All I really want is a true JavaScript language that compiles into .NET. This is a very important think to me in that it would make a seamless language transition between the client and server environments.


  • WGParrish

    I wanted to provide an update to anyone who sees this.  I discovered a cool subset of JavaScript that truely appears to be the same across all the languages.

    JScript on the server side has serious limitations because in ASP .NET you cannot take the system out of /f fast mode without causing serious problems.  The Microsoft documentation does a good job of explaining the new class statement, but the new class statement makes all "function" statements static.  This makes it so you can't redefine them during TDD sessions.

    Well,  I realized that you can still use JScript .Net to create good ole-fashioned dynamic objects in JScript .NET.... The trick, ... just don't name them.

    Write the object like this:

    var myObj = new Object;

    myObj.MyMethod = function () {
        return "Hello World";
    }

    What I do is to put the whole thing in my own constructor function like this:

    function newHelloWorld() {
         var myObj = new Object;
         myObj.MyMethod = function() {
              return "Hello World";
         }
         return myObj;
    }

    This object can now be used like this:

    var o = newHelloWorld();
    Response.Write(o.MyMethod());

    or

    document.write(o.MyMethod()) ;

    depending on where you are server or client.

    This code should work both in the browser and on the IIS with ASP .NET server.  You don't have to compile it on either the client and the server(cool! and it's so dynamic!).  I am planning to upgrade my JSNUnit to demonstrate this common language subset.  I plan to use the same code both client and server and just use a <script src="..."> tag to link to the same code both client and server.  I decided to post here first because I don't want to stay up all night tonight trying to change JSNUnit.

     

     


  • One Standard: JavaScript Both Client and Server. Is it Possible today?