ProtoViewLogic: getOwnerOf()

与えられた要素を所有する ProtoViewLogic を取得します。

要素が relateElements() 関数によって ProtoViewLogic と関連付けられている場合、その ProtoViewLogic の参照を取得できます。

このメソッドは静的メソッドです。

構文

ProtoViewLogic.getOwnerOf(element) => ProtoViewLogic

引数

  • element: Element

    所有する ProtoViewLogic を調べる対象の要素です

返値: ProtoViewLogic | undefined

与えられた要素 element を関連付けている ProtoViewLogic です。 もし関連付けられた ProtoViewLogic がない場合、undefined を返します。

const vl      = new ProtoViewLogic();
const span    = document.createElement("span");
const buttons = [ document.createElement("button"), document.createElement("button") ];

//  所有者の取得; undefined が返る
console.log(ProtoViewLogic.getOwnerOf(span));
//  ==> undefined

//  vl と span を関連付ける
vl.relateElements({ span });

//  所有者の取得; vl が返る
console.log(ProtoViewLogic.getOwnerOf(span) === vl);
//  ==> true 

//  vl と buttons を関連付ける
vl.relateElements({ buttons });

//  所有者の取得; vl が返る
console.log(ProtoViewLogic.getOwnerOf(buttons[0]) === vl);
//  ==> true
console.log(ProtoViewLogic.getOwnerOf(buttons[1]) === vl);
//  ==> true

解説

与えられた要素を所有する ProtoViewLogic を取得します。

引数 elementProtoViewLogic が関連付けられているなら、その ProtoViewLogic を返します。そうでないなら undefined を返します。

info

よく似たメソッドに ProtoViewLogic.getRelationshipOf() があります。 getRelationshipOf() では所有者である ProtoViewLogic に加えて、どのようなプロパティ名で関連付けられているか、配列として関連付けられている場合、その配列上のインデックスを返します。プロパティ名とインデックスが必要な場合、getOwnerOf() の代わりに getRelationshipOf() を使うようにしてください。