[Javascript] Objects vs. Classes

Philip Thompson philthathril at gmail.com
Fri Dec 11 09:11:46 CST 2009


Hello all.

I currently use Mootools as my javascript library. When I was first learning it, I instantiated classes to perform certain related classes. Then I shifted to just creating objects. What's the main difference between the two? 

classes:
var SomeClass = new Class ({
    Extends: [Options, Events],
    options: {...},
    aMethod: function () {...},
    anotherMethod: function () {...}
});

js objects:
var SomeObject = {
    someId: '...',
    someMethod: function () {...},
    anotherMethod: function () {...}
};

Essentially, a class is a javascript object (in the terminology I'm using here, at least). With the class, you can extend and implement other classes (at least with this particular library). What are the other differences? Speed? Memory? Etc...

Thanks,
~Philip


More information about the Javascript mailing list