JavaScript 的替代品 [英] Alternatives to JavaScript

查看:18
本文介绍了JavaScript 的替代品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,唯一完全支持的语言以及浏览器中 DOM 树操作的事实标准是 JavaScript.看起来它有很深的设计问题,使其成为新手的漏洞和安全漏洞的雷区.

At the moment, the only fully supported language, and the de-facto standard for DOM tree manipulation in the browser is JavaScript. It looks like it has deep design issues that make it a minefield of bugs and security holes for the novice.

您是否知道任何现有或计划中的举措来为下一代浏览器中的 DOM 树操作和 HTTP 请求引入任何类型的更好(重新设计)语言(不仅是 JavaScript)?如果是,它集成到 Firefox 的路线图是什么?如果不是,出于什么原因(除了互操作性)JavaScript 应该是浏览器平台上唯一支持的语言?

Do you know of any existent or planned initiative to introduce a better (redesigned) language of any kind (not only javascript) for DOM tree manipulation and HTTP requests in next generation browsers? If yes, what is the roadmap for its integration into, say, Firefox, and if no, for what reasons (apart of interoperability) should be JavaScript the only supported language on the browser platform?

我已经使用过 jQuery,并且我还阅读了javascript:好的部分".这些建议确实很好,但我无法理解的是:为什么只有 javascript?在服务器端(您最喜欢的操作系统平台),我们可以使用每种语言来操作 DOM 树,甚至是 Fortran.为什么客户端(浏览器平台)只支持javascript?

I already used jQuery and I also read "javascript: the good parts". Indeed the suggestions are good, but what I am not able to understand is: why only javascript? On the server-side (your-favourite-os platform), we can manipulate a DOM tree with every language, even fortran. Why does the client side (the browser platform) support only javascript?

推荐答案

javascript 的问题不在于语言本身——它是一种完美的原型化和动态语言.如果您具有面向对象的背景,那么学习过程会有些困难,但这不是语言的错.

The problem with javascript is not the language itself - it's a perfectly good prototyped and dynamic language. If you come from an OO background there's a bit of a learning curve, but it's not the language's fault.

大多数人认为 Javascript 类似于 Java,因为它具有相似的语法和相似的名称,但实际上它更像 lisp.它实际上非常适合 DOM 操作.

Most people assume that Javascript is like Java because it has similar syntax and a similar name, but actually it's a lot more like lisp. It's actually pretty well suited to DOM manipulation.

真正的问题是它是由浏览器编译的,这意味着它的工作方式因客户端而异.

The real problem is that it's compiled by the browser, and that means it works in a very different way depending on the client.

不仅实际 DOM 因浏览器而异,而且在性能和布局方面也存在巨大差异.

Not only is the actual DOM different depending on the browser, but there's a massive difference in performance and layout.

编辑以下有问题的说明

假设支持多种解释语言 - 您仍然遇到相同的问题.各种浏览器仍然有问题并且有不同的 DOM.

Suppose multiple interpreted languages were supported - you still have the same problems. The various browsers would still be buggy and have different DOMs.

此外,您必须在浏览器中内置一个解释器,或者以某种方式安装为每种语言的插件(您可以在提供页面之前检查).使 Javascript 保持一致需要很长时间.

In addition you would have to have an interpreter built into the browser or somehow installed as a plug in (that you could check for before you served up the page) for each language. It took ages to get Javascript consistent.

您不能以相同的方式使用编译语言 - 那么您将引入一个无法轻易检查其功能的可执行文件.许多用户会选择不让它运行.

You can't use compiled languages in the same way - then you're introducing an executable that can't easily be scrutinised for what it does. Lots of users would choose not to let it run.

好的,那么编译代码的某种沙箱怎么样?对我来说听起来像 Java Applet.或 Flash 中的 ActionScript.或 Silverlight 中的 C#.

OK, so what about some sort of sandbox for the compiled code? Sounds like Java Applets to me. Or ActionScript in Flash. Or C# in Silverlight.

某种IL标准怎么样?那有更大的潜力.使用您想要的任何语言进行开发,然后将其编译为 IL,然后由浏览器进行 JIT.

What about some kind of IL standard? That has more potential. Develop in whatever language you want and then compile it to IL, which the browser then JITs.

除此之外,Javascript 已经有点像 IL - 只需查看 GWT.它允许您使用 Java 编写程序,但将它们分发为 HTML 和 JS.

Except, Javascript is kind of already that IL - just look at GWT. It lets you write programs in Java, but distribute them as HTML and JS.

在进一步澄清问题后进行编辑

Javascript 不是,或者更确切地说,不是浏览器支持的唯一语言:回到 Internet Explorer 的黑暗时代,您可以选择 Javascript 或 VBScript 以在 IE 中运行.从技术上讲,IE 甚至没有运行 Javascript - 它运行 JScript(主要是为了避免支付 Sunjava 这个词,Oracle 仍然拥有这个名称 Javascript).

Javascript isn't, or rather wasn't, the only language supported by browsers: back in the Internet Explorer dark ages you could choose between Javascript or VBScript to run in IE. Technically IE didn't even run Javascript - it ran JScript (mainly to avoid having to pay Sun for the word java, Oracle still own the name Javascript).

问题是 VBScript 是 Microsoft 的专利,但它也不是很好.虽然 Javascript 正在添加功能并在其他浏览器(如 FireBug)中获得顶级调试工具,但 VBScript 仍然只支持 IE 并且几乎不可调试(IE4/5/6 中的开发工具不存在).与此同时,VBScript 也扩展为操作系统中非常强大的脚本工具,但这些功能在浏览器中均不可用(并且当它们成为巨大的安全漏洞时).

The problem was that VBScript was proprietary to Microsoft, but also that it just wasn't very good. While Javascript was adding functionality and getting top rate debugging tools in other browsers (like FireBug) VBScript remained IE-only and pretty much un-debuggable (dev tools in IE4/5/6 were none existent). Meanwhile VBScript also expanded to become a pretty powerful scripting tool in the OS, but none of those features were available in the browser (and when they were they became massive security holes).

仍然有一些公司内部应用程序使用 VBScript(有些依赖于这些安全漏洞),而且它们仍在运行 IE7(它们只是停止了 IE6,因为 MS 最终将其杀死了).

There are still some corporate internal applications out there that use VBScript (and some rely on those security holes), and they're still running IE7 (they only stopped IE6 because MS finally killed it off).

让 Javascript 达到目前的状态是一场噩梦,并且花了 20 年的时间.它仍然没有一致的支持,一些浏览器仍然缺少语言特性(在 1999 年指定)并且需要大量的垫片.

Getting Javascript to it's current state has been a nightmare and has taken 20 years. It still doesn't have consistent support, with language features (specified in 1999) still missing from some browsers and lots of shims being required.

在浏览器中添加用于解释的替代语言面临两个主要问题:

Adding an alternate language for interpreting in browsers faces two major problems:

  • 让所有浏览器供应商实施新的语言标准——这是他们 20 年来仍未为 Javascript 管理的东西.

  • Getting all the browser vendors to implement the new language standard - something they still haven't managed for Javascript in 20 years.

第二种语言可能会削弱您已有的支持,允许(例如)IE 获得第二流的 Javascript 支持,但(再次)出色的 VBScript.我真的不想为不同的浏览器编写不同语言的代码.

A second language potentially dilutes the support you already have, allowing (for instance) IE to have second rate Javascript support but great VBScript (again). I really don't want to be writing code in different languages for different browsers.

应该注意的是,Javascript 还没有完成"——它仍在不断发展以在新的浏览器中变得更好.最新版本领先数年浏览器的实现,他们正在研究下一个.

It should be noted that Javascript isn't 'finished' - it's still evolving to become better in new browsers. The latest version is years ahead of of the browsers' implementations and they're working on the next one.

这篇关于JavaScript 的替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆