KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In a particular script I'm writing, I have a number of objects which are linked to some DOM Elements. Given that each element has a unique id, should each object keep just the element's id (and use document.getElementById each time), or store the element in a property? Here's a simplified example of what I mean: 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; }; Does it make any difference? Are there any performance issues I should know about?
Tags (comma-separated)
Save Edits
Cancel