Library vs Framework 1 – JavaScript Design Patterns

Library vs Framework 1 – JavaScript Design Patterns


Now let’s take a few minutes to unpack the words, library and framework. Now, this is another difficult topic to cover because of the inconsistencies. You see, it’s not a single person or entity defining these two words. It’s a community. And so, the usages of these words in the community can be a lot more loose. Now, you may have heard the word framework used when describing CSS frameworks. But we’re going to remove those from the discussion. CSS frameworks generally are not JavaScript, although they sometimes include it. And including CSS frameworks in the discussion just confuses everything.>From here on forth, I’m just talking about purely JavaScript libraries. So, what’s a library? A library is just a bunch of JavaScript that someone else or some other people wrote, packaged up, and distributed. Or in fact, it could be JavaScript that you wrote and packaged up. There are a lot of things we do over and over again as developers, like making AJAX requests and manipulating the DOM. And as we do this again and again, we don’t want to have to keep writing the same code over and over again. In this case here, I’ve decided not to rewrite it three more times for three more projects. And instead, I set aside this AJAX code for reuse in all of my projects. Libraries take it one step further. Rather than have every developer write their own AJAX function, why not just make an AJAX library and distribute it freely for everyone to use? And while we’re at it, why not make a library that makes DOM manipulation easier too? Now, that’s exactly what people actually do. If you search on the web, you’ll find all kinds of AJAX libraries and all kinds of DOM manipulation libraries. jQuery is a great example of a library for DOM manipulation, AJAX, and much more. Now, don’t be confused by all of my colors here. All I’m bringing out is that jQuery has an AJAX library built into it and a DOM manipulation library built into it. If you really wanted to, you could probably separate these things out and make them work separate from the rest of jQuery. We’re not going to do that, but it is important to keep in mind that everything in jQuery is just some JavaScript that some other people wrote already. And we can use it rather than rewriting all of its functionality from scratch ourselves. And what’s more, the good libraries will often make allowances for older browsers, abstracting away some of the browser differences and issues so you can spend time focusing on building your app rather than supporting older browsers. So, now we know what a library is. It’s just a bunch of code that someone else wrote that we can use in our application. Now, when we talk about libraries and frameworks in this class, we’re generally talking about organizational libraries and frameworks. And jQuery here is not an organizational library. It does give us a bunch of useful great methods. But it doesn’t give us anything to help us organize our code.

Only registered users can comment.

Leave a Reply

Your email address will not be published. Required fields are marked *