admin管理员组文章数量:1325510
Hi I have this two objects in javascript
var john = { firstname: 'John', lastname: 'Smith' }
var jane = { firstname: 'Jane' }
doing this:
jane.__proto__ = john;
I can access to jane's properties and also john's properties
If __proto__
is not supported in IE8 for example, what's the equivalent to write this:
jane.__proto__ = john;
Thanks!
Hi I have this two objects in javascript
var john = { firstname: 'John', lastname: 'Smith' }
var jane = { firstname: 'Jane' }
doing this:
jane.__proto__ = john;
I can access to jane's properties and also john's properties
If __proto__
is not supported in IE8 for example, what's the equivalent to write this:
jane.__proto__ = john;
Thanks!
Share Improve this question edited Mar 2, 2013 at 15:26 Josh Unger 7,1737 gold badges37 silver badges55 bronze badges asked Sep 14, 2012 at 21:01 rgx71rgx71 8676 gold badges21 silver badges32 bronze badges2 Answers
Reset to default 9There is no equivalent or standard mechanism in IE. (The __proto__
property in Firefox is non-standard extension as is not specified in the ECMAScript standards.)
The [[prototype]] object can only be specified by setting the prototype
property upon the function-object which acts as the constructor before the construction of a new object. The [[prototype]] can, however, be mutated later.
Anyway, here is a little example of specifying a [[prototype]] from an existing object. Note that the [[prototype]] assignment must be done before the new object is created. ECMAScript 5th edition introduces Object.create which can do the following and shallow-clone an object.
function create (proto) {
function f () {}
f.prototype = proto
return new f
}
var joe = create({})
var jane = create(joe)
joe.name = "joe" // modifies object used as jane's [[prototype]]
jane.constructor.prototype === joe // true
jane.__proto__ === joe // true -- in Firefox, but not IE
jane.name // "joe" -- through [[prototype]]
jane.constructor.prototype = {} // does NOT re-assign jane's [[prototype]]
jane.name // "joe" -- see above
__proto__
currently is not an standard use.
Following the ECMAScript standard, the notation someObject.[[Prototype]] is used to designate the prototype of someObject. Since ECMAScript 5, the [[Prototype]] is accessed using the accessors Object.getPrototypeOf()
and Object.setPrototypeOf()
.
So you could use getPrototypeOf()
to access.
As in chrome,
> Object.getPrototypeOf(Object) === Object.__proto__
< true
本文标签: internet explorer 8Using javascript proto in IE8Stack Overflow
版权声明:本文标题:internet explorer 8 - Using javascript __proto__ in IE8 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742196906a2431245.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论