Javascript 在不同浏览器中的功能有何不同?

发布于 2024-12-02 03:05:59 字数 184 浏览 0 评论 0原文

我认为我不需要提供示例,因为每个 Web 开发人员都知道您需要测试 Javascript 以确保它在不同浏览器之间兼容。我不明白的是为什么。 JavaScript 不是 JavaScript 吗?这就像 .NET 框架在一台计算机上的行为与在另一台计算机上的行为不同一样。任何人都可以阐明这一点,可能会提供一些源链接来配合他们的答案吗?

I don't think I need to provide examples because every web developer knows that you need to test your Javascript to make sure it's compatible across different browsers. What I don't get is why. Isn't Javascript Javascript? It'd be like the .NET framework behaving differently on one computer than it does on another. Can anyone shed some light on this, possibly with some source links to go along with their answer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

网名女生简单气质 2024-12-09 03:05:59

简而言之,每个浏览器都会为 JS 编写自己的解释器

长答案

要理解为什么编程语言的功能不同,您必须了解编程语言在执行时会发生什么。首先,有两种类型的语言:解释型和编译型。编译语言在执行之前从人们可读的“代码”转变为机器代码,并以二进制形式分发。

解释型语言是即时编译的,JS 就是其中之一。即时编译语言意味着什么?好吧,计算机只能理解 1 和 0,因此所有高级语言都必须分解为指令,然后分解为二进制。当某些内容被动态编译时,它会编译一行,然后运行它,然后编译下一行。 (当然有一些错综复杂的地方,但这确实是它的缺点)

因为 JS 直到最近才真正有了一个独立的解释器,而浏览器是 JS 的主要目的,每个公司都必须编写自己的解释器来进入他们的浏览器。 Microsoft、Mozilla、Netscape……每个人都需要思考如何处理某些事情,然后执行它们。

因为这两件事先发生,所以如果两个人一起工作,你永远不会得到同样的东西。想想当您学习计算机科学课程时,每个人都必须制作一个计算器应用程序,但每个人都采取不同的方法。这种情况在 js 中经常发生,并导致一些浏览器在爬行,而另一些浏览器却在飞。

第二个是公司固步自封,他们在翻译上投入了太多的时间和精力,在修改作品时不想从头开始,而且更便宜。这意味着过去 JS 较少使用且对 Web 开发不再那么重要时出现的差异将继续存在,因为当它以自己的解释器为中心时,使用 webkit 推出全新版本的 IE 确实很困难多年来。

The short answer is every browser writes it's own interpreter for JS

The long answer

To understand why a programming language functions differently you have to understand what happens to a programming language at execution. First there are two types of languages interpreted and compiled. Compiled languages are turned from people readable "code" to machine code before execution and distributed as a binary.

Interpreted languages are compiled on the fly, JS is one of those languages. What does it mean to compile a language on the fly? Well, a computer can understand nothing but 1's and 0's and because of this all higher level languages must be broken down to instructions and then binary. When something is compiled on the fly it compiles a line, then runs it, then compiles the next. (of course there are intricacies but that really is the short of it)

Because JS really has never had a stand alone interpreter until recently, and the browser is JS's main purpose every company had to write their own interpreter that would go into their browser. Microsoft, Mozilla, Netscape... Everyone needed to think of how certain things could be handled and then execute them.

Because of this two things happen first, you are never gonna get the same thing if two people are working on it. Think about when you take an intro to Comp Sci course everyone has to make a calculator app but everyone takes a different approach. That happens all the time with js, and causes some browsers to crawl while others fly.

The second is that companies get set in their ways, they have too much time and energy invested in their interpreter and don't want to start over when modifying works and is cheaper. This means that differences that arose in the past when JS was less used and no where near as critical to web development will remain just because it's really difficult to roll out a whole new version of IE with webkit when it has been centered around it's own interpreter for years.

灼疼热情 2024-12-09 03:05:59

阅读此内容 -> http://www.quirksmode.org/js/intro.html 有很多JavaScript 实现的版本 - 它们都有差异。

Read this -> http://www.quirksmode.org/js/intro.html there are lots of version of the JavaScript implementation - all of them have differences.

脱离于你 2024-12-09 03:05:59

每个浏览器都有不同版本的 Javascript,有些浏览器仅实现每个版本的某些功能。以下是 IE9 的发行说明,其中指出 javascript 在 IE8 上的执行方式有所不同和IE9。

这是版本列表

Each browser has a different version of Javascript, and some implement only certain features of each version. Here are the releases notes for IE9, that state javascript performs differently on IE8 and IE9.

Here is a list of versions.

蓝颜夕 2024-12-09 03:05:59

通常,不同的浏览器之间的javascript语言并没有什么不同,问题是DOM、HTML和事件在不同的浏览器中是不同的。
一些javascript库可以帮助减少差距,即:jQuery(仅减少差距)

usually, there is not different of javascript language between different browser, the problem is that DOM, HTML and event are different in different browsers.
some javascript library can help reduce gap, ie: jQuery (only reduce gap)

以为你会在 2024-12-09 03:05:59

嗯,javascript 实际上是 EcmaScript 的子集,EcmaScript 是标准推荐。该建议在浏览器中的实施仅取决于编辑者的意愿。这导致一些实现(javascript、jscript、v8 等)在某些情况下表现不同。除此之外,不同浏览器的布局引擎也不同(gecko、trident、webkit 等),您会发现使用 javascript 并不那么简单;)。

Well, javascript is in fact a subset of EcmaScript which is a standard recommendation. The implementation of this recommandation among the browsers depends only of the willingness of the editors. This leads to several implementation (javascript, jscript, v8, etc...) all behaving differently in certain cases. Add to this that the layout engine differs from browser to browser (gecko, trident, webkit, etc...) and you'll see that it's not that simple to use javascript ;) .

记忆里有你的影子 2024-12-09 03:05:59

事实上,.NET 的行为确实有所不同,具体取决于您使用的实现(Microsoft 的还是 Mono)。

也就是说,这与 Javascript 相同,除了一个小例外,标准是一个不断变化的目标。它是由 Netscape 早先引入的,部分被 Microsoft 复制为 JScript,部分由 ECMA 标准化,并由浏览器供应商独立扩展,每个浏览器供应商对于 Javascript 中的好主意都有自己的想法。

很难定义 Javascript。现在所有浏览器中通常作为基准实现的是称为 Javascript 1.5 又名 ECMA-262 第三版的功能集。浏览器供应商(和其他人)正在开发一种称为 ECMAScript 5 的东西,但它会持续数年,直到所有浏览器都完全支持它。

当然,每个浏览器在其实现中都有自己的错误。最(臭名昭著)的例子之一是 IE 中的尾随逗号:

// works in all browsers:
var a = [1, 2, 3]
// works in all browsers but IE
var b = [1, 2, 3,]

Well, as a matter of fact, .NET does behave differently, depending on which implementation (Microsoft's or Mono) you use.

That said, it is the same with Javascript, with the small exception, that the standard is a moving target. It was introduced back in the days by Netscape, copied partly by Microsoft as JScript, standardized partly by ECMA and extended independently by the browser vendors, each one with their own idea of what would be a good idea to have in Javascript.

It's hard to define the Javascript. What is usually implemented as a baseline in all nowadays browsers is the feature set known as Javascript 1.5 aka ECMA-262 3rd edition. The browser vendors (and others) work on something called ECMAScript 5, but it will last years, until all browsers support this fully.

And then of course, every browser has its own bugs in its implementation. One of the most (in-)famous examples is the trailing comma thing in IE:

// works in all browsers:
var a = [1, 2, 3]
// works in all browsers but IE
var b = [1, 2, 3,]
菩提树下叶撕阳。 2024-12-09 03:05:59

Internet Explorer有JScript,这是微软自己的JavaScript实现。他们不遵循任何规范的故事由来已久。

至于其他人 - 他们用 JavaScript 实现自己的函数和对象。例如,您有一个理论上的函数 foo,并且它在每个浏览器上都是相同的名称。但写法不同。这可能会导致执行时间或其他方面的差异。

另一件事 - 每个浏览器都有自己的特定功能。没有人可以强迫他们不拥有这样的东西。

Internet Explorer has JScript, this is Microsoft own JavaScript implementation. They have a long story of not following any specifications.

As for the others - they make their own implementations of the functions and objects in JavaScript. For example you have a theoretical function foo, and it is the same name on every browser. But the way it is written is different. Which may cause difference in the time for the execution or something else.

One other thing - every browser has its own specific functions. Nobody can force them not to have such.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文