When is __proto__ useful?
When is __proto__
useful?开发者_如何学JAVA
A lot of browsers support it, but because not all do, programmers seem to be scared of using it. I've never seen it in any code (such as the libraries jQuery and backbone.js).
When is __proto__
useful? Is it just a geeky thing for completeness?
__proto__
is deprecated and should not be used. Use Object.getPrototypeOf
instead. See https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/Proto - But Opera supports __proto__
and not Object.getPrototypeOf
, so beware.
That said, Object.getPrototypeOf
is, like the name says, used to get the prototype of an object. I've never found this useful yet.
Edit 2012-02-06 Opera supports Object.getPrototypeOf
as of 11.60
.
It is useful if you are going to modify an objects prototype and need to find out if it has been already modified.
Note that __proto__
is deprecated, instead you should is Object.getPrototypeOf
.
MDN Documentation on proto
精彩评论