Browsed by
Tag: Javascript

2 hours of Video on JavaScript from Douglas Crockford

2 hours of Video on JavaScript from Douglas Crockford

I spend a lot of time doing web development in my daily life. I am employed as a software engineer, and as part of that employment, I get the opportunity to program in JavaScript from time to time. I’ll be the first to admit that I am not great at it, as the language was never formally “taught” to me. Because of this, I have found several interesting parts of the language that have caused me some problems over time. Below are several links to videos containing instruction from Douglas Crockford on the do’s and dont’s of the JavaScript language, which I found very informative, given the problem I ran into a while ago on the project I am working on.

The problem I had to solve was introduced by another programmer, and that is: he did not formally declare a variable, but instead just started using it. Obviously, I did not discover this until much later, however. Unfortunatly, this variable was set up as a counter, and because the name was generic, it was used in several functions to accumulate the count within different functions. The person who originally programmed it did not know any better, and probably thought that while odd, since javascript allowed him to use the variable without issue, that it must be ok.

Well, it turns out, I got the task of debugging this particular code, which was throwing some sort of “index out of bounds” error that no one could find. After many days of beating my head against the problem, it turned out that instead of declaring var i = 0; in some places, “i” simply came in to use, and was never formally declared. When I found this problem, the var declaration added to the variable fixed the problem, but I never really knew what was going on in the first place to cause the problem, because the error was showing up in different methods, which didn’t make sense because of my presumptions about scope in JavaScript.

It turns out, if you don’t formally declare a variable in JavaScript, but instead just start using it, the scope for that variable is global. I discovered this only recently, after watching a great series on JavaScript by Douglas Crockford. The series is available via Yahoo!’s video service, and is entitled “The JavaScript Programming Language”.

The series is about 2 hours in length, and covers a vast amount of JavaScript nuances and gotchas, and is highly recommended for even the seasoned JavaScript programmer. Douglas Crockford also is the author of a very cool tool you may be familiar with, called JSLint. This tool is very interesting, in that it will tell you more about your JS programming habits than you ever wanted to know. It is a great tool, and I highly recommend investigating these tools to help you become a better JS programmer.

Yahoo Charts and Firefox

Yahoo Charts and Firefox

Recently, Yahoo.com upgraded their finance section to use new interactive charts. You may remember because I previously wrote about it here. These new charts offer technical analysis options and many things investors typically have to pay for, and all for free. With these new charts, anyone can plot 15 minute delayed bollinger bands, MACD crossover, Simple moving averages and stochastics all for free. One issue I was having is that none of these grand new features work in Firefox. Yahoo charts seemed to be broken for use with firefox, and that frustrated me.

After nearly 2 months of not being able to access the dropdown menu for technical features of the Yahoo charts in firefox, I decided to look into the problem more. It appeared to me to be some sort of javascript issue, where my browser was blocking the javascript pop-down menu for the technical tools bar. I have javascript enabled in my browser, because the internet pretty much doesnt work without javascript at this point, so it wasn’t that. Then it hit me.

I use the Ad-Block plugin for firefox, which is kinda touchy when it comes to javascript popups. I disabled Ad-Block and the interactive yahoo charts work like a dream.

I realize that some of you may think I am being a hypocrite for serving Google ads on my website, while simultaneously running ad-block in my web browser, but I only run Ad-Block on certain computers which I consider to need more of a secure browsing experience. My normal laptop for which I am typing this now, does not use adblock for the express purpose that I DO sometimes click on ads if they are relevant to what I am doing. Anyway, hope this tip helps!