This javascript tutorial covers the javascript object literal pattern for web developers. We’ll cover how to build a basic module in javascript.
The object literal pattern is also shown in this great e-book by Addy Osmani: http://addyosmani.com/resources/essentialjsdesignpatterns/book/#modulepatternjavascript
The simplest pattern for modular javascript is the object literal pattern – it adds all values and methods on a single object, thus encapsulating all of the module’s function into one object. The downside of this pattern, is it leaves all of the module’s data accessible.
Modular JS #2 – Object Literal Pattern pt 2:
Modular JS #3 – Revealing Module Pattern:
Original source
41 responses to “Modular Javascript – Javascript Tutorial on the Object Literal Pattern”
Thanks for not having an impossible to understand Indian accent.
Love our videos
I keep getting an unrecognized syntax error highlight the mustache tags on HTML, even after setting the type='text/template' on the script tag
Thank you!
This really is the perfect tutorial.
i was really confused but you made my life easy thanks alot man really nice explaination
I love all of your tutorials, but the baby/kid voice in the background is a bit distracting 🙂 Thanks for making these though!
wow…..thank you
Hi ,you can download the code for this tutorial ? THANK YOU !!!
note: @7:20 for test purposes, define object literals outside of document ready method!
#revisited. hands down one of the best tutorial playlists regarding modular, inheritance, object literal, revealing, oop etc for js imo.. thanks again.
amazing
Thank you!
Just keep in mind that for some use cases this would actually be an anti pattern. This is not a reusable component. You cannot instantiate a new one with a new name and age for example.
Do you guys plan to create a patreon or link to a donate page? I really like the quality of the videos and I want to support you guys directly. Keep up the great work!
Thanks for the clear and concise explanation. Favorite and subscribed. Thanks for taking the time to do this.
You are JavaScript GOD for me….!!
I wanted to learn how to code those "objects with functions thingies" that I saw in a lot of well written code but didn't know how it was called so I was stuck, and I found this vid (already a subscriber but I still have a LOT of vids to watch !). Now I know how it's called and I can finally get rid of those spaghettis that litter my code and step up my game.
I have sent you a private message Will . 🙂
Thank you so much for your tutorials! I struggled to learn this pattern at first being that I am quite new to programming but after watching a few times my code is looking super sexy in my projects!
Awesome! How would you do this same concept with ES6 using class? Thanks
Love this series. Awesome.
Wow.. this is really, really good. Excellent introduction!
VERY similar to OOP but less TYPE-ing,
Awesome tutorial, thank you
Awesome content !!!
excellent video, but I did not see the unbind event in the following video. do I miss something
Fantastic video series! Its helped me learn so much more about JS that I've always wanted to know about, but had no idea where to start.
I have a question about the 5:15 point of the video regarding no memory leaks. I'm up to video #4 – PubSub, but I do not recall the no memory leaks ground rule being addressed/further explained. Have I just missed it, or will it be addressed in a later video?
Not the worse code I've seen. I associate spaghetti code with goto statements. I still have nightmares of a fortran 66 program I had to translate to java.
this is a gem… devs should really must watch thi…
Thank you for sharing! Very useful concepts…
Great series! Very usefull thanks!
Would love to get the source code for this tutorial. And a tutorial on how to turn the "spaghetti" code from your previous jQuery tutorials into modules. For example the image-slider or tabbed panel, maybe an image slider inside the tabbed panels all using modules. In those tutorial you talk about caching the DOM and with modules i dont see how i do that.
what is the difference between modularJS, backboneJS, nodeJS ?
Are there any dis/advantages to declaring functions the "traditional" way as opposed to using function expressions? Excellent series, by the way. Thanks, Will.
anyone? who has a copy of the complete index page? I can't seem to follow it
How far should I go with this idea? I have a To Do List app that's about 400 lines of JS. Right now it's separated into about thirteen functions and ten global variables. Would it be wise to put all of this code into one module?
This is awesome. The structure is absolutely beautiful.
Hire me pls.
This is the best video I've seen on OOP and making logical components. Awesome channel.
Can you share the html and css files associated with this tutorial?