for the sake of brevity, assume the the situations am referring to all occur within the same context and scope.
I began to ponder about this possible issue when toying around with some .js:
function testX(){ alert ('!'); } // this is also equivalent to: testX=function (){ alert ('!'); }
testX = 10;
Begin used to PHP, I would have expected that you could have a variable AND a function that, essentially, share the same name. Of course, thats not the way .js works; there is only ONE testX which contains the value of 10 Still, it really rubs me the wrong way that .js behaves this way. it’s just a minor thing, mind you, having little impact on how i code and probably stemming from me having had my formative programing experiences using PHP.
But one thing does strike me as ‘fragile’…
The DOM automatically creates a named object element for every HTML element with an ID.
In other words, given :
<div id='anExample'>Sample content<div>
don’t HAVE to do this :
alert (document.getElementByID('anExample').innerHTML);
since, anExample is already an element the dom… you can simplify the above to:
alert (anExample.innerHTML);
GREAT! That’s kinda convenient, but now it makes em wonder…
what is going to happen if I or someone else give IDs to elements in the markup that , inadvertently, coincide with variable/function names in some of the imported/or applied scripts in that page? How is integrity maintained?
eg.:
<script type="text/javascript"> aVal='i need to be TEXT';</script>
<div id='aVal'>Sample content</div>
or
<script type="text/javascript"> function foo(){ alert('am a crucial function!!!'); } </script>
<div id='foo'>Sample content</div>
Scotty if I am being vague, I haven’t encountered a difficulty with this yet, just thinking theoretically. but I just wanted to know what you guys thought about this, if any one had run into issues, and how you had resolved them.