简体   繁体   English

Javascript:哪些浏览器支持原型 inheritance?

[英]Javascript: Which Browsers support prototype inheritance?

Currently I'm not using prototype because I remember that a day I've read an article where it was stated that Prototype is not supported in IE 7 and down below, but I can't find that article again but by the way it would be good to know how it is supported overall.目前我没有使用原型,因为我记得有一天我读过一篇文章,其中指出 IE 7 及以下版本不支持原型,但我无法再次找到那篇文章,但顺便说一句它会很高兴知道它是如何得到整体支持的。

JScript (Microsoft's interpretation of Javascript) has supported the prototype property since version 2.0 ( MSDN ). JScript(微软对 Javascript 的解释)从 2.0 版( MSDN )开始支持原型属性。 The first version of Internet Explorer that supported JScript 2.0 was IE 3 ( MSDN ).支持 JScript 2.0 的第一个 Internet Explorer 版本是 IE 3 ( MSDN )。

I'd say you're safe with IE7!我会说你用IE7是安全的!


Edit: perhaps you're thinking about modifying the prototypes of host objects, such as Node .编辑:也许您正在考虑修改主机对象的原型,例如Node This is indeed not supported by IE >=7, and is a bad idea anyway. IE >=7 确实不支持这一点,无论如何都是个坏主意。 A good article on this is at perfectionkills.com .关于这方面的一篇好文章在 perfectkills.com 上

The attribute .prototype exists in all JS implementations, otherwise it wouldn't be Javascript.属性.prototype存在于所有 JS 实现中,否则不会是 Javascript。 ECMA-262 December 1999: ECMA-262 1999 年 12 月:

Objects对象

ECMAScript does not contain proper classes such as those in C++, Smalltalk, or Java, but rather, supports constructors which create objects by executing code that allocates storage for the objects and initialises all or part of them by assigning initial values to their properties. ECMAScript 不包含适当的类,例如 C++、Smalltalk 或 Java 中的类,而是支持通过执行为对象分配存储空间并通过为其属性分配初始值来初始化全部或部分对象的代码来创建对象的构造函数。 All constructors are objects, but not all objects are constructors.所有构造函数都是对象,但并非所有对象都是构造函数。 Each constructor has a Prototype property that is used to implement prototype-based inheritance and shared properties.每个构造函数都有一个 Prototype 属性,用于实现基于原型的 inheritance 和共享属性。 Objects are created by using constructors in new expressions;对象是通过在 new 表达式中使用构造函数来创建的; for example, new String("A String") creates a new String object.例如,new String("A String") 创建一个新字符串 object。 Invoking a constructor without using new has consequences that depend on the constructor.在不使用 new 的情况下调用构造函数会产生依赖于构造函数的后果。 For example, String("A String") produces a primitive string, not an object.例如,String("A String") 生成原始字符串,而不是 object。

According to their downloads page , the current version of Prototype (1.7) is compatible with the following browsers:根据他们的下载页面,当前版本的 Prototype (1.7) 与以下浏览器兼容:

Browser         Version(s)
Mozilla Firefox ≥ 1.5
Microsoft Internet Explorer for Windows ≥ 6.0
Apple Safari    ≥ 2.0.4
Google Chrome   ≥ 1.0
Opera           ≥ 9.25

update更新

IE7 definitely supports prototype inheritance. IE7 绝对支持原型 inheritance。

If you mean the Prototype library, then Prototype's download page states that it is compatible with IE6 and higher.如果您指的是 Prototype 库,那么Prototype 的下载页面声明它与 IE6 及更高版本兼容。

[EDIT] [编辑]

Your question edit makes the question very confusing.您的问题编辑使问题非常混乱。 When you say "the real Javascript Prototype", what do you mean?当您说“真正的 Javascript 原型”时,您是什么意思? Do you mean the feature of Javascript which allows you to add methods and properties to classes (eg String.Prototype.trim = function() {...} ) then yes, this is a basic property of the language, and has existed since the very begining, so yes it would be supported in IE7.您是说 Javascript 的功能,它允许您向类添加方法和属性(例如String.Prototype.trim = function() {...} )那么是的,这是语言的基本属性,并且从那时起就存在一开始,所以是的,它会在 IE7 中得到支持。

According to the Prototype website , it's compatible with IE6+, and a whole host of other browsers.根据Prototype 网站,它与 IE6+ 以及许多其他浏览器兼容。 However, I rarely use it so I can't talk from experience.但是,我很少使用它,所以我不能从经验中谈起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM