[英]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.