object caching in modern JavaScript?

34 Views Asked by At

I'm preparing to take a JavaScript test, and came upon this post: http://www.javascriptkit.com/javatutors/efficientjs.shtml

The gist is that this:

<script type="text/javascript">
for (var i=0;i<document.images.length;i++)
    document.images[i].src="blank.gif"
</script>

is not as efficient as this:

<script type="text/javascript">
var theimages=document.images
for (var i=0;i<theimages.length;i++)
    theimages[i].src="blank.gif"
</script>

because the object is 'cached' in a user defined variable.

Is this still the situation with modern JavaScript engines?

0

There are 0 best solutions below