为什么 javascript 是浏览器中实现的唯一客户端脚本语言?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8946906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 08:10:50  来源:igfitidea点击:

Why is javascript the only client side scripting language implemented in browsers?

javascriptbrowserwebstandards

提问by anand.trex

Why don't browsers add support for, say, Python scripting as an alternative to Javascript? Or more general purpose scripting languages? Is there a reason that Javascript is the only one implemented across browsers? After all, the script tag does have support to specify the scripting language used.

为什么浏览器不添加对 Python 脚本的支持来替代 Javascript?或者更通用的脚本语言?Javascript 是唯一跨浏览器实现的,是否有原因?毕竟,脚本标签确实支持指定使用的脚本语言。

(I know there is VBScript support in IE, but it seems obsolete for all intents and purposes.)

(我知道 IE 中有 VBScript 支持,但它似乎已经过时了。)

采纳答案by vcsjones

Well, Google is trying to buck that trend with Dart. The community hasn't been entirely receptive to the idea; either.

好吧,谷歌正试图用Dart来扭转这一趋势。社区还没有完全接受这个想法。任何一个。

Google proposed adding multiple VM support for Webkitwhich didn't go down very well.

Google提议为 Webkit 添加多个 VM 支持,但效果不佳。

One particular comment summed it up nicely as to why there has been some resistance to that:

一个特别的评论很好地总结了为什么会有一些阻力:

In this case the feature is exposing additional programming languages to the web, something without any real benefit to anyone other than fans of the current "most awesome" language (not too long ago that might have been Go, a year or so ago this would have been ruby, before than python, i recall i brief surge in haskell popularity not that long ago as well, Lua has been on the verges for a long time, in this case it's Dart -- who's to say there won't be a completely different language in vogue in 6 months?), but as a cost it fragments the web and adds a substantial additional maintenance burden -- just maintaining the v8 and jsc bindings isn't trivial and they're for the same language.

The issue here isn't "can we make multiple vms live in webkit" it's "can we expose multiple languages to the web", to the former i say obviously as we already do, to the latter I say that we don't want to.

Unless we want to turn webkit into the engine that everyone hates because of all its unique "features" that break the open web, a la certain browsers in the late 90s.

在这种情况下,该功能正在向网络公开其他编程语言,除了当前“最棒”语言的粉丝(不久前可能是 Go,大约一年前,这将一直是 ruby​​,在 python 之前,我记得不久前我也曾短暂地流行过 Haskell,Lua 已经处于边缘很长一段时间了,在这种情况下它是 Dart——谁说不会有6 个月内流行的完全不同的语言?),但作为成本,它会分散网络并增加大量额外的维护负担——仅仅维护 v8 和 jsc 绑定并不是微不足道的,而且它们是针对同一种语言的。

这里的问题不是“我们可以在 webkit 中创建多个虚拟机吗”而是“我们可以向网络公开多种语言吗”,对于前者,我显然已经这样做了,对于后者,我说我们不想要到。

除非我们想把 webkit 变成每个人都讨厌的引擎,因为它所有独特的“功能”打破了开放的网络,就像 90 年代后期的某些浏览器。

CoffeeScript is another example of an emerging client-side scripting language. However, rather than support another virtual machine in a browser (as Google is trying to do with Dart), it compiles to JavaScript. There are several other "compile X to JavaScript" that do that as well. emscriptenis a good example of compiling LLVMto JavaScript.

CoffeeScript 是新兴的客户端脚本语言的另一个例子。然而,它不是在浏览器中支持另一个虚拟机(就像 Google 试图用 Dart 做的那样),而是编译为 JavaScript。还有其他几种“将 X 编译为 JavaScript”也可以做到这一点。emscripten是将LLVM编译为 JavaScript 的一个很好的例子。

So there are plenty of other client languages; they just all use JavaScript as an intermediate. I'd argue that should be what Dart does as well, though they have some room to improve.

所以还有很多其他的客户端语言;他们都使用 JavaScript 作为中间体。我认为这也应该是 Dart 所做的,尽管他们还有一些改进的空间

回答by Martin Broadhurst

Internet Explorer supports any Windows Script Engine, so you can make it support any language that has been implemented as one, or write your own.

Internet Explorer 支持任何Windows 脚本引擎,因此您可以使其支持任何已作为一种语言实现的语言,或者编写您自己的语言。

回答by Quentin

Because JavaScript is what every other browser supported, and browser vendors had two main priorities:

因为 JavaScript 是其他所有浏览器都支持的,浏览器供应商有两个主要优先事项:

  1. Making sure existing webpages worked (which requires JavaScript)
  2. Letting authors do user visible things in their browser that they couldn't do in other browsers (changing programming language would be entirely hidden from users, except when it broke).
  1. 确保现有网页正常工作(需要 JavaScript)
  2. 让作者在他们的浏览器中做用户可见的事情,而他们不能在其他浏览器中做(更改编程语言将对用户完全隐藏,除非它坏了)。