简体   繁体   English

如何在客户端和服务器之间重用我的JavaScript代码?

[英]How can I reuse my javascript code between client and server?

I have some javascript code that includes an ANTLR-generated lexer and parser, and some associated syntax tree evaluation functionality. 我有一些JavaScript代码,其中包括ANTLR生成的词法分析器和解析器,以及一些相关的语法树评估功能。 This code runs in the browser in my web app to support users who author code snippets which process scientific data. 此代码在我的Web应用程序的浏览器中运行,以支持编写处理科学数据的代码段的用户。

Now I'd like to do some additional background processing on the server using the same generated parser. 现在,我想使用相同的生成解析器在服务器上进行一些其他的后台处理。 I would prefer not to have to re-implement this stuff in C# and have multiple bits of code that did the exact same thing. 我宁愿不必在C#中重新实现此功能,也不必使用多个代码来执行完全相同的操作。 Performance isn't as critical to me as eliminating duplication, since this is a background process. 对于我来说,性能并不是消除重复的关键,因为这是一个后台过程。 So, how can I call into my javascript code from C#? 那么,如何从C#调用我的JavaScript代码? And how can I format my script so that it plays nicely with my .NET web app? 以及如何格式化我的脚本,使其与.NET Web应用程序完美配合?

Anyone who wants to do this who isn't running Windows should definitely check out node.js . 想要在不运行Windows的情况下执行此操作的人一定应该签出node.js。 Unfortunately for your purposes, I don't think the Windows port is working yet. 不幸的是,出于您的目的,我认为Windows端口尚未运行。

For server-side JS usage in general, CommonJS is trying to standardize how libraries are created and used. 通常,对于服务器端JS的用法, CommonJS试图标准化创建和使用库的方式。 You can also find links there to a lot of server-side Javascript implementations. 您还可以在此处找到许多服务器端Javascript实现的链接。

Update: node.js will now work under CygWin . 更新:node.js 现在将在CygWin下工作 I'm not sure how much work it would be to integrate it into your environment though. 我不确定将其集成到您的环境中将花费多少工作。

您可以看看 JScript.NET,尽管与传统(客户端)JavaScript(ECMA)会有(至少一些)差异。

I have two idea's: 我有两个主意:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何禁用中继并将代码用作经过身份验证的客户端? - How can i disable the relaying and use my code as an authenticated client? 使用具有两种相同但名称不同的两种类型的API。 如何重用我的代码? - Consuming an API which has a two types which are the same but have different names. How can I reuse my code? 如何让我的客户端 - 服务器应用程序成为多客户端服务器应用程序? C# - How can i make my client-server app a multiclient-server app? C# 如何重用从.NET客户端到Apache服务器的SSL连接 - How to reuse SSL connection from .NET client to Apache Server 如何获取C#中服务器与客户端之间的延迟? - How do I obtain the latency between server and client in C#? 链接基础构造函数时,如何在重载中重用初始化代码 - When chaining a base constructor, how can I reuse initialization code in an overload TCP如何将数据包从客户端中继到服务器 - TCP how do I relay the packets from my client to the server 为什么我的客户端服务器udp代码未发送? - Why is my client server udp code not sending? 我可以在不断开服务器连接的情况下重用HttpWebRequest吗? - Can I reuse HttpWebRequest without disconnecting from the server? 如何从C#代码进入SQL Server存储过程? - How can I step into a SQL Server stored proc from my C# code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM