Friday, January 25, 2008

setTimeout / setInterval and object scope

I have found over time, the need for setTimeout/setInterval is pretty rare... however, when the need does arrive, it is an invaluable tool!

The problem that I have consistently run into as of late (now that I am writing primarily object based JavaScript) is that when you use these functions, you loose the scope of your object. (i.e. if you call setTimeout(this.myFunc,900); this no longer refers to your object, but rather window, causing your script to fail). In search of a solution, I found an interesting article by Kelvo.

Klevo points out that in FireFox, setTimeout allows you to pass an additional parameter stating the implied scope. So by simply changing our command to: setTimeout(function(that) { that.methodToCall(); }, time, this); fixes the issues with scope... We basic create a proxy function that accepts an object as it's only paramater and gives us access to of that functions methods! This is a beautiful solution, if all you are developing for is FireFox.

From there, I found Alex's article who gives a simple yet elegant workaround for IE as well.

Check it out, it's absolutely worth a read for anyone who has run into trouble with setTimeout and JavaScript objects.

Tuesday, January 15, 2008

What's in a dream?

So, last night I had this crazy, yet very vivid dream... My wife and I were having this party at our house... well, it was more like a mix between our house and Jen's parents house... anyway, at some point during the party this kid, couldn't have been older than 14, who I didn't recognize got really upset in one of the back rooms... Needless to say he pulled a gun and tried to shoot the people around him. Thankfully he only grazed the arm of one, the rest were able to get out of the way. As I went running into the room, the kid stepped into the bathroom and proceeded to shoot himself. When I stepped into the bathroom I remember my spirit crying out.. "Nooooo! God, you can't let this happen! If he dies now he will end up in Hell!"... I stepped closer to him, and he was indeed dead, no pulse, no breathing. All I could think to do was pray... "In the name of Jesus" I said as I laid my hands on this boy, and instantly he took a deep breath... I stepped back, almost scared... "What happened? I was dead... My body was being torn apart...", he said quickly and out of breath. "God didn't think you were ready to die, He brought you back to live... He has a purpose for your life...", I replied. The kid jumped to his feet, and I took a couple steps back... he ran towards me and wrapped his arms around my neck... "No one has ever told me I had purpose... no one has ever believed I could do anything" He said as tears were rolling down his face. He proceeded to run though the house hugging every freaked out person, telling them how God brought him back from the dead and how He has purpose for everyone...

That's about all I remember... At this moment tears are running down my face. I don't know why I had this dream... I don't know what it means... A friend of mine told me that maybe I am supposed to pray for this kid... I don't even know his name... So if you are out there Kid, I am here, praying that God will restore the life in you, that He will show you purpose, that He loves you despite everything you have done or been through.

"I can do all things through Him who strengthens me." -- Philippians 4:13 (NASB)

Wednesday, January 9, 2008

Sending out some props to Nick Hauenstein for his fantastic work on finally a site where you can not only read the Bible and find research material, but you can track your reading progress, write notes about every verse if you like, and share them with the world or just keep them all for yourself. This is the creme de la creme for online Bible studies with a group of people! Finally, God's Word meats social networking (well, sorta).

Tuesday, January 8, 2008

Safari for Windows????

How ridiculous I thought... Safari for windows? Who in their right mind would even consider that???? Most Mac users don't even like Safari!!! But, I figured as a matter of standards I better try it... cause I'm gonna have to start supporting it... Here's the thing... I actually think they have done an excellent job! This is not the Safari that I am used to... it's clean, responsive (maybe even more responsive than FireFox...), AND... it even passes the elusive Acid 2 test!... well, almost... Who knew!?! Now, it's only in beta for windows at this point, but even at that I am starting to like it... So far every site I have visited has seemed much more responsive and every site I have built and tuned for FireFox has worked without a hitch! The jury is still out on this one for me, but I am happy to welcome this new contender to the ever growing browser battle! (that statement may come back to bite me some day ....)