简体   繁体   中英

JScript.NET vs ECMA

I am programming a small console app that is an intelligent front-end to a set of batch files with ungodly parameters.

I have decided to use JScript.Net for this though it may be ill advised compared to C# because I am finding the flexibility of it useful, and it feels a bit more RAD than C# for this kind of thing.

The problem I have is not being able to find adequate resources on the net showing how JScript.Net != ECMA when it gets down to the nuts and bolts level. I have to be constantly vigilant of the gotchas, and how things are actually implemented are a bit puzzling.

Does anyone have good links to information on this subject?

Edit--

To be specific, I want a resource that will stop me from writing tests like this -- which compiles and runs, despite the weirdness going on in the synax:

var int16:Int16=0;
w_(typeof int16);                // =number
//w_(int16.getType());    //runtime error function expected
//
var ds:String="dot,net,class";
w_(typeof ds);                   // =string
var da1:Array=ds.Split(',');  // proper case
var da2:Array=ds.split(',');  // camel case !works too!
w_(typeof da1);                 // =object
var ds1_:String=da1.join(',');// NOT proper. "Join" is **runtime error**
var ds2_:String=da2.join(',');// NOT proper. "Join" is **runtime error**
w_('ds1_:'+ds1_); // prints dot,net,class
w_('ds2_:'+ds2_); // prints dot,net,class
//
var js="jscript.object";
w_(typeof js);                   // =string
var ja1=js.split(','); // camel case
var ja2=js.Split(','); // proper case
w_(typeof ja1);                   // =object
var js1_=ja1.join(',');// camel
var js2_=ja2.join(',');// camel
w_('js1_:'+js1_);  // prints jscript.object
w_('js2_:'+js2_);  // prints jscript.object
//
// and then
//
var dss:System.String="dot,net,sys,class";
w_('dss:'+(typeof ds));                   // =undefined !!!
//w_('dss:'+dss.getType());    //runtime error function expected
var daa:Array=dss.Split(',');// proper case  ???? what is this object type!
var daa2:Array=dss.split(',');// camel case  ???? what is this object type!
w_(daa.join(','));       // prints dot,net,sys,class
w_(daa2.join(','));       // prints dot,net,sys,class
//

You see?

Also

// in library 'package' JLib_Test.jsc
import System;
import System.IO;
import System.Diagnostics;
import System.Text;
import System.Drawing;
package JLib_Test{
  class Test{
    public function Test(){
      //var re=new RegExp('^s$','gi'); // **runtime error** !
    }
  }
//
// in main 'exe' module
var re=new RegExp('^s$','gi'); // no errors

As you are on Windows, just run your .js file with cscript.exe : this is the Windows Scripting Host (WSH) environment from Microsft that uses the other Microsoft implementation (a standard Windows 7 system has currently 3: JScript, JScript.NET and JavaScript in IE9). The JScript from WSH is the one that was used in IE up to IE8, and so has probably less .NET-isms.

Note that you'll probably have issues with your I/O and argument parsing as the API in .NET and WSH are different, so I suggest to make a common API wrapper.

Do you mean ECMAScript ? ECMAScript is a standard scripting language, standardized by ECMA and JScript.Net is an "implementation" of EMCAScript which has been created by Microsoft (actually based on JScript) to be used upon .Net platform. It means JScript.Net supports all ECMAScript specifications: http://msdn.microsoft.com/en-us/library/49zhkzs5(v=vs.71).aspx

and also provides users with some extra Non-ECMA features: http://msdn.microsoft.com/en-us/library/894hfyb4(v=vs.71).aspx

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