原文:青色表示
訳文:黒色表示
注記/訂正: 赤色表示
The prototype objet that XPConnect creates for the classes that have classinfo are shared within a scope (window). Because of this, the following is true (|img1| and |img2| are two different image objects in the same document):
img1.__proto__ === img2.__proto__
class info を備えているクラスへ XPConnect が生成するプロトタイプオブジェクトは領域(window)内で共用されます。このお陰で、以下の条件は真となります。 (|img1| と |img2| は同じドキュメントの異なる2 つのイメージオブジェクトです):
img1.__proto__ === img2.__proto__
If |img1| comes from one document and |img2| comes from another document then the above is not true, both protos would look identical, but they'd be two different JSObject's.
|img1| と |img2| が別別のドキュメントに由来するならば、上記の条件は真になりません。2 つのプロトタイプは同じに見えますが、2 つの異なる JSObject です。
This sharing of prototypes lets users do cool things like modify how all instances of a given class works by modifying the prototype of one instance. As an example:This sharing of prototypes lets users do cool things like modify how all instances of a given class works by modifying the prototype of one instance. As an example:
function bar()
{
alert("Hello world!");
}
document.images[0].__proto__.foo = bar;
このようにプロトタイプを共有化し、ユーザは、1つのインスタンスのプロトタイプを変更することで、所定のクラスのすべてのインスタンスがどのように機能するかについて、変更など素晴らしいことが実現できます。例を見ましょう:
function bar()
{
alert("Hello world!");
}
document.images[0].__proto__.foo = bar;