私が書いている特定のスクリプトでは、いくつかのDOM要素にリンクされたオブジェクトがいくつかあります。各要素に一意のIDがある場合、各オブジェクトは要素のIDだけを保持し(たびにdocument.getElementByIdを使用するか)、その要素をプロパティに格納する必要がありますか?DOM要素への参照の格納
ここで私が何を意味するかの簡単な例です:
function myThing(elId) {
this.elId = elId;
}
myThing.prototype.getElValue = function() {
return document.getElementById(this.elId).nodeValue;
};
// -- vs -- //
function myThing(elId) {
this.el = document.getElementById(elId);
}
mything.prototype.getElValue = function() {
return this.el.nodeValue;
};
が、それはどんな違いがありますか?私が知るべき性能上の問題はありますか?