Question

Javascript is a prototype-based object oriented language but can become class-based in a variety of ways, either by:

  • Writing the functions to be used as classes by yourself
  • Use a nifty class system in a framework (such as mootools Class.Class)
  • Generate it from Coffeescript

In the beginning I tended do write class based code in Javascript and heavily relied on it. Recently however I've been using Javascript frameworks, and NodeJS, that go away from this notion of classes and rely more on the dynamic nature of the code such as:

  • Async programming, using and writing writing code that uses callbacks/events
  • Loading modules with RequireJS (so that they don't leak to the global namespace)
  • Functional programming concepts such as list comprehensions (map, filter, etc.)
  • Among other things

What I gathered so far is that most OO principles and patterns I've read (such as SOLID and GoF patterns) were written for class-based OO languages in mind like Smalltalk and C++. But are there any of them applicable for a prototype-based language such as Javascript?

Are there any principles or patterns that are just specific to Javascript? Principles to avoid callback hell, evil eval, or any other anti-patterns etc.

No correct solution

Licensed under: CC-BY-SA with attribution
scroll top