owenashurst / agar.io-clone

Agar.io clone written with Socket.IO and HTML5 canvas
MIT License
2.88k stars 1.12k forks source link

Question: why are classes used as module pattern? #456

Open tzhg opened 7 years ago

tzhg commented 7 years ago

I'm learning JavaScript, and I'm confused as to why the Canvas and ChatClient modules are incorporated as classes.

Because they will only be instantiated once, there won't be any need for inheritance.

So what is the advantage of this over the standard module pattern below? Thanks.

var canvas = (function() {
    ...
})();