Background
First of, I would like to mention, that a SO-search for figuring out differences of
- (host objects) DOM-Javascript Objects (
var domJSobj = document.createElement("div")
) and - (native objects) pure Javascript Objects (
var pureJSobj = {}
)
has been done, but still I cannot claim that I found very much (great is, that there is this question-answers: what-is-the-difference-between-native-objects-and-host-objects). Maybe I overlooked something here, then a comment is very appreciated.
I also read MDN Mozillas Docu on DOM and Javascript to get some idea before asking here.
Question
Being a little "glueless" I started playing in the Javascript Console and I encountered some first pitfall (arising from expectations I have regarding the behaviour of (native objects) which are not true for (host objects)). To be clear many things -at first sight- seem similar:
var nativeObject = {}; //create new object nativeObject.someAttribute = "something"; //set some attribute nativeObject.someMethod = function() { return this.someAttribute; } // define some method console.log(nativeObject.someAttribute); // "something" console.log(nativeObject.someMethod()); // "something" var hostObject = document.createElement("div"); //create a "div" one type of host object hostObject.someAttribute = "something"; //set some attribute hostObject.someMethod = function() { return this.someAttribute; } // define some method console.log(hostObject.someAttribute); // "something" console.log(hostObject.someMethod()); // "something"
For me it seems at first sigth that a (host object) is just as usable as a (native object) and has already more:
console.log(nativeObject.tagName); // undefined console.log(hostObject.tagName); // "DIV"
as it has the all the nice DOM-attributes already there.
My Question is about a list of pitfalls (possible troubles) that can arrise if I decide to (mis)use a (host object) instead of simple (native object)?
already I am aware of this:
- speed considerations (I assume that native objects are created more quickly)
- memory usage consideratoins (native objects might be better here too)
Anyways I cannot see much trouble (if those considerations are not very important in a case) yet? This is the reason for the question.
I think answers to this question would be best showing/telling one potential pitfall, that is a case or situation in which it is bad or impossible to use a (host object) over a (native object). In this way this question should adhere to the SO-quality requirement of being passed on real facts and not provoking mere opinion-based-discussion.