微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – 避免在多种不同语言中编写相同的算法

我是一名Web开发人员,我观察到很多次我需要在客户端和服务器上使用相同的功能.所以我用JS以及 PHP或任何服务器端语言编写它.我厌倦了这个.如果我必须改变它,那么我需要在两个地方改变它.如果我想将它用于某些手持设备,那么我将不得不再次使用Objective-C或Java等重写该代码.然后,如果我需要更改该功能,那么我将需要在任何地方更改它.

这有解决方案吗?如果我将通过ajax调用一些web服务,那么客户端将有延迟.如果它将在JS中,则无法从PHP或Java等中访问它.如果我在PHP中使用其他语言的某些服务,那么这也可能成为性能问题.

也有一段时间我们需要使用db或没有db从某些参数输出这些函数作为输入.

我知道会有一些非常简单的解决方案,但我不知道.请告诉我一些语言无关的解决方案,因为我总是没有VPS.

我不确定我的问题是否实际上属于stackoverflow.com或programmers.stackexchange.com所以请将它转移到programmers.stackexchange.com而不是关闭这个问题,如果它属于那里.

解决方法

通常,此问题的解决方案是使用一种语言编写公共代码,并使用转换程序或库链接以允许从其他语言进行访问.

Node.js允许您使用JavaScript编写服务器端代码.

Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast,scalable network applications. Node.js uses an event-driven,non-blocking I/O model that makes it lightweight and efficient,perfect for data-intensive real-time applications that run across distributed devices.

您还可以使用JavaScript为移动设备编写HTML5应用程序.

“Building iPhone Apps with HTML,CSS,and JavaScript”

Now web designers and developers can join the iPhone app party without having to learn Cocoa’s Objective-C programming language. It’s true: You can write iPhone apps quickly and efficiently using your existing skills with HTML,and JavaScript. This book shows you how with lots of detailed examples,step-by-step instructions,and hands-on exercises.

如果您不想尝试在JavaScript中编写大型复杂应用程序,GWT提供了编写Java和通过翻译的方法,在客户端上运行它.

The GWT SDK contains the Java API libraries,compiler,and development server. It lets you write client-side applications in Java and deploy them as JavaScript.

如果您使用.Net语言开发:C# – > JavaScript ScriptSharp

Script# is a free tool that enables developers to author C# source code and subsequently compile it into regular script that works across all modern browsers

原文地址:https://www.jb51.cc/js/158104.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐