auntnini
12-09-2010, 02:17 AM
In a recent post -- http://www.dynamicdrive.com/forums/showthread.php?t=59307 -- I noticed the following code, the syntax of which puzzles me:
<script type="text/javascript">
(function() {
function findwidth(){
var width = document.getElementById('test').offsetWidth;
alert(width); }
if (window.addEventListener){
window.addEventListener('load', findwidth, false);
} else if (window.attachEvent){
window.attachEvent('onload', findwidth); }
})();
</script>
===========================
<script type="text/javascript">
(function(){
var width = document.getElementById('test').offsetWidth;
alert(width);
})();
</script>
Flash EMCA Script version (which seems to be ahead of browser support for JavaScript) has been using addEventListener for a while so I somewhat comprehend that. But the extra (parentheses) encompassing the function is a mystery to me. Can someone point me toward some up-to-date references and/or give me "keywords" to search for?
Also so noted
" ... please post a new question in a new thread .... Do not interrupt an existing thread, especially not before the original person has had a chance to respond to the initial advice."
Forgive me, my trespasses.
<script type="text/javascript">
(function() {
function findwidth(){
var width = document.getElementById('test').offsetWidth;
alert(width); }
if (window.addEventListener){
window.addEventListener('load', findwidth, false);
} else if (window.attachEvent){
window.attachEvent('onload', findwidth); }
})();
</script>
===========================
<script type="text/javascript">
(function(){
var width = document.getElementById('test').offsetWidth;
alert(width);
})();
</script>
Flash EMCA Script version (which seems to be ahead of browser support for JavaScript) has been using addEventListener for a while so I somewhat comprehend that. But the extra (parentheses) encompassing the function is a mystery to me. Can someone point me toward some up-to-date references and/or give me "keywords" to search for?
Also so noted
" ... please post a new question in a new thread .... Do not interrupt an existing thread, especially not before the original person has had a chance to respond to the initial advice."
Forgive me, my trespasses.