Last Updated: March 09, 2020
·
2.561K
· lautarodragan

Learning JavaScript Design Patterns

Over the last five years, I have been doing more and more javascript. It was inevitable: at first, the simple need to handle a click in a website. Then AJAX came, and I just couldn't understand who would want to do old-style sites that reload all the time anymore, instead of doing a nice ajaxy site.
And now, the possibility of developing pretty much anything in javascript is mind-blowing.

As we went from simple inline javascript to fully-featured games and dynamic websites, the need for maintainable code raised more and more.

But applying what most of us have learned for deeply structured, object oriented languages such as Java or C# in js is not that easy.

So here's a little gem: Learning JavaScript Design Patterns, a book by Addy Osmani

THANKS FOR READING

If you enjoyed this protip, consider reading my other protips. I also blog, and would love you to read some BUILD FAILURE :)

6 Responses
Add your response

It's not function-oriented, it's object-oriented, it's just prototype-based http://en.wikipedia.org/wiki/Prototype-based_programming

over 1 year ago ·

@khasinski Thanks, you're right.

over 1 year ago ·

One more interesting thing about javascript code maintenance is the lack of implied file organization. I actually spent quite a long time having just one folder with everything (the dredded /js) until I realized I could organize them however felt natural. That led to the problem of subjectivity, what I feel natural might not be the same as my colleague. In languages that enforce (or heavily invites) to some sort of convention is much easier to maintain just because files are located where you expect them to.

over 1 year ago ·

@alexanderbrevig Indeed, javascript doesn't seem to force the programmer to do anything at all. I still have my /js </code> folders actually, and only recently I decided (by experience only) to use a one file - one class design. Learning Require.js is one of my pending subjects... and I'll see how I organize the files after that.

over 1 year ago ·

@lautarodragan I still use /js or /scripts as well, just realized I could do /js/models /js/modules etc :) stupid really, but that's life. Also, when I first tried Require.js I neglected to do the optimization where Require appends all scripts to one file and minifies it and then the cache is used for clients. That made it a much better tool! I discovered it after I reverted to server side configuration of what files to include. I'll try it again soon though :)

over 1 year ago ·

@alexanderbrevig That's where javascript libraries and frameworks can help - experienced developers of those frameworks use design patterns and well structured code. Take a look at Dojo Toolkit and YUI library. There is so much you can learn from their source code.

over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip