What are people using JScript.Net for?

前端 未结 12 1712
清酒与你
清酒与你 2020-12-23 13:50

I\'m interested to know who uses JScript.Net and for what sort of applications. Whenever I\'m reading MSDN .Net documentation, I always notice the JScript samples but in all

相关标签:
12条回答
  • 2020-12-23 14:34

    I don't know how it compares performance-wise, but I know that JScript.NET is one of the languages you can use with Unity 3D.

    0 讨论(0)
  • 2020-12-23 14:36

    As an enhancement for batch files and for console applications as it allows a neat hybridization (without unnecessary output) thanks to its directives.Save the following example with .bat extension and check its result:

    @if (@X)==(@Y) @end /* JScript comment
    @echo off
    setlocal
    
    for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d  /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do (
       set "jsc=%%v"
    )
    
    if not exist "%~n0.exe" (
        "%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0"
    )
    
     %~n0.exe %*
    
    endlocal & exit /b %errorlevel%
    
    
    */
    
    import System;
    
    Console.WriteLine("hello from jscript.net");
    

    Here some examples can be found.

    0 讨论(0)
  • 2020-12-23 14:38

    The JScript.NET Wikipedia page is pretty explanatory: http://en.wikipedia.org/wiki/JScript_.NET

    In short, it seems to be JavaScript with the .NET library.

    0 讨论(0)
  • 2020-12-23 14:41

    Well, I'm trying to use it. I can't say I've been successful.

    I've not done a lot of web coding in any environment, but here is my 2 cents.

    I wanted to expose some database tables to a web page, so I threw together a quick Classic ASP (yeah, yeah, I know) page that pulled the data from SQL Server and returned the table as a JSON object. Rather than locate a JSON serializer for VBScript I just wrote both sides in J(ava)script and imported json2.js on the server to provide serialization. It worked great; honestly it took less than an hour to have it spit back a nice JSON representation of the table, 50 minutes of which was a fruitless attempt to get JScript to import json2.min.js directly rather than throwing <% %> wrappers around it and renaming it json2.min.asp.

    But everyone says it is sick and wrong to use Classic ASP in this day and age, so I'm trying to replace my quick & dirty ASP + Jscript + ADO implementation with ASP.NET + Jscript.NET + ADO.NET. After some head-pounding-keyboard moments I have ASP.NET v4.0.30319 up on IIS6 and have a "hello, world" page that does some simple loops javascript via the <@ language = "JScript"> directive. So far so good.

    I were following Best Practices here I'd be wrapping everything in a class etc, but as I'm just try to get out of the driveway I tried doing a quick port of my existing code, which imports various useful bits of Javascript from other files using ASP include statements.

    Including some simple stuff using <--#incude file="somejsconstants.asp" --> worked fine and let me access constants from that file. But my attempt to pull in the JSON serializer with<--#incude file="json2.min.asp" --> didn't work, and firing up a version of json2.js suitably modified to be a standalone aspx page and threw the same error. (The compiler error is Objects of type 'jscript_aspx' do not have such a member.) JScript.NET seems to be unhappy with the use of closures, a near-omnipresent construction in today's javascript libraries.

    From postings above it's clear there are plenty of ways to serialize JSON objects in the .NET platform, but my gut feeling is that if JScript.NET barfs on Javascript written by Douglas Crockford, then it is a quirky, incompatible rathole not worth investing my time in. I might as well follow the ASP.NET masses and use C#.

    0 讨论(0)
  • 2020-12-23 14:47

    Rob - I have used JScript.NET in anger in one place in my code, which is essentially to expose the functionality of its eval method. Here is a cut-down version:

    static public class Evaluator
    {
        private const string _jscriptSource =
            @"package Evaluator
            {
               class Evaluator
               {
                  public function Eval(expr : String) : String 
                  { 
                     return eval(expr); 
                  }
               }
            }";
    
        static private object _evaluator;
        static private Type _evaluatorType;
    
        static Evaluator()
        {
            InstantiateInternalEvaluator();
        }
    
        static private void InstantiateInternalEvaluator()
        {
            JScriptCodeProvider compiler = new JScriptCodeProvider();
    
            CompilerParameters parameters;
            parameters = new CompilerParameters();
            parameters.GenerateInMemory = true;
    
            CompilerResults results;
            results = compiler.CompileAssemblyFromSource(parameters, _jscriptSource);
    
            Assembly assembly = results.CompiledAssembly;
            _evaluatorType = assembly.GetType("Evaluator.Evaluator");
    
            _evaluator = Activator.CreateInstance(_evaluatorType);
        }
    
        static public object EvaluateToObject(string statement)
        {
            try
            {
                return _evaluatorType.InvokeMember(
                    "Eval",
                    BindingFlags.InvokeMethod,
                    null,
                    _evaluator,
                    new object[] {statement}
                    );
            }
            catch (Exception)
            {
                InstantiateInternalEvaluator();
                return null;
            }
        }
    

    You can obviously create overloads for other return types. I can't claim the original idea for this was mine! Uses for this would be, for example, to evaluate a string expression like 3 + 4 to 7 without expression parsing.

    0 讨论(0)
  • 2020-12-23 14:48

    With the Business Process Management tool Metastorm BPM you can use JScript.Net to extend your workflows. For example you can add custom .Net .dlls to the engine and interact with them in your processes using JScript.Net.

    My experience was quite positive. I've implemented just some small glue scripts but I'd prefer scripting with JScript.Net to VBScript (the second supported Scripting Language) anytime.

    0 讨论(0)
提交回复
热议问题