Understanding scope in JavaScript object oriented programming

When you think of the keyword this you probably assume it refers to the current instance of the class. This is true for most object oriented programming like C# and Java.
For example I could use the this keyword in C# like this:

class Cat {
string _name;
public Cat(string name) {
this._name = name;
}
}

In the above example you see this illustrated. In C# and Java, this always refers to the class instance.

So, knowing this you would probably assume the same would be true of object oriented programming in JavaScript and it's this keyword. This is, however, not the case. Like a lot of things about writing object oriented code in JavaScript, this behaves differently in some situations. this does not always refer to the class instance depending on how you use it.

function Cat(name) {
this.Name = name;
}

In the above object oriented programming example it works just like our C# example but look at a situation where things can go wrong if you are unaware of some rules.

( Read more )

Happy Fifth Birthday, Gmail


2004: Google unveils Gmail. It will change webmail… and a few other things as well.

Five years ago, if we wanted to talk to somebody halfway around the world, we'd open up Outlook, Eudora or some other bulky piece of software on our desktops and type an e-mail.

Most of us had webmail, which was a convenience on the road since we could access it from any computer, but it wasn't enjoyable. Web inboxes were slow and cumbersome, messy with checkboxes and radio buttons, and often so riddled with spam they had to be emptied frequently lest they reach capacity.

Gmail changed all that. It was fast and elegant just like a desktop app. There was so much storage, you never had to delete anything. In fact, you couldn't — there wasn't even a Delete button! And you didn't miss the Delete button since it was almost entirely spam-free.

Gmail was so slick and easy to use, many of us switched to it full-time and have never gone back.

On its fifth birthday, it's difficult to ignore the enormous influence Gmail has had not only on web-based e-mail services, but on rich web applications in general. Several of the concepts introduced by Gmail, which were at the time on the bleeding edge of application design, have since been adopted by the web's mainstream.


( Read more )

MVC Framework and jQuery = Ajax heaven

I've got an admission to make: I've never used any of the Microsoft Ajax Toolkit. But recently I've been adding some mapping functionality to the project I'm working on. We wanted users to be able to pull a marker to a position on a map and have the new position updated on the server. Obviously we were going to have to use Ajax of some kind to do that. What I want to show today is how trivially easy it's proved to be to use MVC Framework on the server and jQuery on the browser to do Ajax requests and updates. JQuery is now included in the default project for the MVC Framework, so there's no excuse not to use it.

Here's a very simple scenario. I've got a a page where I want to show a list of people when I click 'Get People'. I also want to add a person to the database when I type their name into a text box and click 'Add Person'. Here's what it looks like:




( Read more )

AJAX, Web 2.0 and SEO

AJAX offers some incredible new functionality for web sites, but it is not SEO-friendly by default. However, you can still successfully optimize a site that uses AJAX and Web 2.0 technologies. This article discusses some of the problems and solutions for AJAX SEO.

Recently a colleague of mine and I were discussing the topic of AJAX and SEO, and he needed some solutions for a web site he was developing. After our discussion, I realized that there is a lot of confusion about search engine optimization and Web 2.0 technologies. That prompted me to share my input on this topic. To start, lets discuss an article I recently read at Search Engine Watch entitled “Web 2.0 Technologies and Search Visibility” about AJAX / Web 2.0 and Search Engine Optimization.


( Read more )

Get Google and AJAX to Play Nice

The best ways to incorporate the benefits of AJAX without making your site blind to search engines.

«If you build it, they will come.» It seemed to work for Kevin Costner in Field of Dreams, but when it comes to your AJAX website, a great design just isn't enough to bring in an audience.

AJAX gives developers the ability to build dynamic web applications without the need for constant server side script parsing, enabling you to provide users with simulated «load on demand» sites. That means shorter page loading times, a sharp decrease in bandwidth consumption and more accessible information in general.

Unfortunately, developers are often so focused on creating a dynamic web page, that they forget that most website traffic today comes through search engines, search engines which have a hard time crawling and indexing the JavaScript in standard AJAX sites. In plain english, that means that in Google's eyes, many of your AJAX site's pages are invisible when it comes to search engine ranking. Compounding the problem is the fact that standard AJAX implementations use only a single page or URL for the majority of actions, meaning that not only are your site's pages indexed poorly, but that your site also has fewer pages in Google's index.

( Read more )