Skip to main content

Javascript For Loop troubles

Ah just got another good tip when doing for loops.

When you do this....

for(var i = 0; i < array.length; i += 1) {
? //bla bla
}

The length of the array is accessed on every loop. Slow! Slow especially when going through HTMLCollection objects.

This can get round that problem...

for(var i = 0; max = array.length; i < max; i += 1) {
? //bla bla
}

According to Stefanov this can increase the performance up to 190 times in IE7. That's a big difference!

Comments

Popular posts from this blog

Specflow

After listening to .Net Rocks with Scott Millett this week I felt a renewed enthusiasm for trying out some BDD. I downloaded Specflow and got straight on with the screen cast they have on their website. The video acts as a good introduction into how to get up and running in Specflow. Interestingly it also gave me a better insight into how bowling works. I have never really thought about it. I normally just wang the balls down the lane until the game is over! Specflow introduces the idea of writing the specification first. It uses a specific language called Gherkin which comes from Ruby land. You will need NUnit installed as well. An example of it is:  [edit: NUnit is what I have used up to now but Specflow is compatible with other testing frameworks aswell. See the comments section below.] Feature : Passwords In order to have a strong password As a new user or existing user changing my password I need to check if my password is alphanumeric and is greater than 6 characters Scenario

Motorola MC65

We have a new PDA in town now. As a replacement for the army of MC9000 and MC70s that are in the field and are being discontinued, we now are moving up to the Motorola MC65. I have had the new handheld for about a week now and have been impressed so far. It's a great improvement over the MC70. I have no idea how the numbering system of the Symbol / Motorola devices works. I assume there must be several ranges such as the 50s 60s and 70s.? Anyway the?PDA?has windows mobile 6.5.3, a better touch screen and is faster. Much faster. The skin that has been put on the OS has also applied to our software and I think it makes it look much cooler. We had several problems in adjusting our software so it would work with the new MC65. First was the change in resolution. The MC70 has a much lower resolution than the MC65s and as some of our screens were not using the auto scale settings in the form and some of the buttons on our forms were created at run time rather than design time, this posed

Accessing the UI Thread with Tasks in F#

I have a Windows Forms program written in F# that can deploy a code base to n number of sites at once (you select the sites you would like to deploy to and it goes off and completes a number of tasks (backing up current sites, various unpacking and moving of files etc... ). Once you start it, it begins it's merry journey and begins to update the UI with what has happened. At the moment this method of updating the UI is not pretty because the threads I am doing the work on can't update the UI so I perform some fiendery to make that happen (don't ask). I knew there was a better way using some newer .NET features but I just hadn't got round to having a fiddle yet. I have now found that if you use the built in Task class but break your code up in a nicer way and then chain the tasks together you can then pass the correct context into the task that you want to talk to the UI. Here's a little script to give you a feel for it. You can press the "start" butt