iite0q
Last Updated: February 25, 2016
·
2.16K
· 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: <a href="http://addyosmani.com/resources/essentialjsdesignpatterns/book/">Learning JavaScript Design Patterns, a book by Addy Osmani</a>

<h2>THANKS FOR READING </h2>

If you enjoyed this protip, consider reading <a href="https://coderwall.com/p/u/lautarodragan">my other protips </a>. I also blog, and would love you to read some <a href="http://www.buildfailure.co">BUILD FAILURE</a> :)

Say Thanks
Respond

6 Responses
Add your response

404
10534 128567884189 828694189 2287781 3877042 n

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 ·
407

@khasinski Thanks, you're right.

over 1 year ago ·
413
Feb007acc38e70d57f7b4c205f7e8b26

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 ·
414

@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 ·
415
Feb007acc38e70d57f7b4c205f7e8b26

@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 ·
6536
388d93e

@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 ·