Do you know how to simulate a class in JavaScript?

You use a constructor function like this:

function DogConstructor(name) { = name;
    this.respondTo = function(name) {
        if( == name) {

var spot = new DogConstructor(“Spot”);
spot.respondTo(“Rover”); // nope
spot.respondTo(“Spot”); // yeah!

If you’ve attended any of my recent MSDN events, here’s a link to the OOP Javascript article that I recommended – it’s a great read! 

Link to JavaScript: Create Advanced Web Applications With Object-Oriented Techniques — MSDN Magazine, May 2007

Comments (0)