I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...
We should be linking to the actual sources of info, rather than just the top google hit.
ReplyDeletehttp://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Reserved_Words
JSscript 8.0:
http://msdn.microsoft.com/en-us/library/ttyab5c8.aspx
I'll look for ECMAScript links later.
This is one of the many things discussed in "JavaScript: The Good Parts" by Douglas Crockford.
ReplyDeleteBy the way, I'm not affiliated with the publisher; The book is just that awesome.
I discovered today that the word "keywords" is a reserved word in IE javascript. It turns out to be an object that contains a list of all the keywords. No errors are generated if you try and use this as a variable, but any time you try and access the value of your variable you get an object back instead of what you assigned to it. Arg!
ReplyDeleteheader and footer just broke my script in IE8.
ReplyDelete