JS library vs Js framework

Leonidas Dosas
Leonidas Dosas used Ask the Experts™
on
I looked at expert-exchange and other sites and videos but I am little confusing...I have some blind spots about the main differences of these two.
  1. Is the library a "tank" of functions that we can call every time that we need these?
  2. Is the framework a single function that we use to to do some event?
  3. Why the majority of libraries starts with an IIFE function?
If there is an article to explain with a plain words the main guide to build a library please post it.
Thank a lot
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
IIFE - this creates privacy
(function() {
})()

Creates a scope around the function so that anything declared in that scope is private to that scope.

Library - a collection of functions that can be called together or independently to perform specific operations. Functions can be called in isolation without necessarily having to perform any configuration or initialisation (Example: jQuery)

Framework imposes a structuring on the code - you construct your code around the rules of the framework.

Simply put - when you use a library you are in control of what you use and how - with a framework - you are under the control of how the framework does things.

References
http://benalman.com/news/2010/11/immediately-invoked-function-expression/
http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#question-about-surrounding-parentheses
https://en.wikipedia.org/wiki/Immediately-invoked_function_expression
http://www.programcreek.com/2011/09/what-is-the-difference-between-a-java-library-and-a-framework/
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
If there is an article to explain with a plain words the main guide to build a library please post it.
This is pretty open ended. A library can be as simple as

function addTwoNumbers(a, b)
{
   return a+b;
}

Open in new window


If you want write a plugin for a library lie jQuery there are many tutorials on line to show you how to do this.

Bottom line - many ways to skin this cat - you would need to be more specific in terms of what you are trying to achieve.
Distinguished Expert 2017

Author

Commented:
Thanks a lot Julian. As a matter of fact I'm trying to go one step beyond at my js knowledge studying some js libraries and frameworks at github. My problem is to understand the basics guidelines about what is performed these two things and the  logic of code construction. I read eg that jquery library returns wrapper functions to manipulate the DOM elements..and I wondering about the way that jquery is doing this.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
The jQuery library relies on the fact that almost every jQuery function returns a jQuery object - this allows us to chain jQuery functions together.

Each function takes the input performs whatever function is required and then returns a jQuery object that gives access to the next call to a jQuery function.

A good library to look at is Datatables - it is quite comprehensive and written well.
Distinguished Expert 2017

Author

Commented:
Maybe is a change for someone to do a beginners guide  article about libraries and frameworks in javascript. I see a lot of excellent codes that I can't determined how they structured.
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
There is a lot of opportunity for this but the landscape is exploding so rapidly difficult to come up with something that retains relevance.

With frameworks like Angular and React (which is more of a library) along with Hybrid environments like Cordova and Appcelerator etc - JavaScript development is going exponential with new ideas coming out regularly. When one writes such an article in order for it to have practical value in terms of a "how-to" it is going to need to be quite specific in what it targets.

For instance we could narrow the focus down to DOM manipulation - but the argument there is that jQuery already has this space covered so use jQuery and make your library in accordance with jQuery guidelines.

If such an article was to be written though - what would you ideally like to see in it?
Distinguished Expert 2017

Author

Commented:
I would like to see the follow:
1. Definition
2. General guidelines structure and design.
3. A simply example for each of these
4. An  explained example like datatables  that you posted.
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
A simply example for each of these
Just to clarify "each" - can you give me a list
Distinguished Expert 2017

Author

Commented:
One simly example for framework and one for library
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Ok - will give it some thought.
Distinguished Expert 2017

Author

Commented:
Thank a lot. As you understood I made a indirect request to you about the article. I hope I am not adding you an adittional effort, but I think that this article is going to be usefull not only for me but and to others experts.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial