How is jQuery built?

1

As you know, jQuery is an open-source JavaScript library whose intent is to facilitate the manipulation of DOM elements by abbreviating the code to be used to perform operations and procedures, where often in so-called "pure JavaScript" we would spend more bytes of code and would be more complicated to do.

As expressed in its slogan " write less, do ", as this library can handle all the complex JavaScript language (functions, methods, etc.) in "few" bytes of 84.6KB)? What is the logic or system used in the jQuery source code that "replaces" the browser's "pure JavaScript"?

    
asked by anonymous 21.11.2017 / 04:37

2 answers

1

jQuery has an engine base for selecting DOM objects. This engine returns the encapsulated objects in jQuery's own objects. Home These jQuery objects that encapsulate DOM objects are extensible and can handle DOM objects. In other words, it is possible to create extensions to do basically anything. Home Another great balcony is working well with the dynamism of javascript, passing whole objects as configurators and passing anonymous functions as a form of callback functions.
The issue of "do more, code less" does not have much to do with the size of the file is ... (which, incidentally, only has this size because it was compressed, the decompressed version has more than 200) did a job so well done of encapsulation and extensibility, that with a single line you do things that would have required 20, maybe even 100 lines of code.

    
21.11.2017 / 10:47
5
  

How this library can span the entire complex JavaScript language (functions, methods, etc.)

Simple, it does not do this.

The text seems to indicate that you think jQuery replaces JavaScript, when in fact it's just a set of functions like any other. In the background it's just utilitarian functions that do the bulk of the work inside of it and leaves you to just pass the parameters, that is, fill in the gaps, which is exactly the reason we create functions.

Functions exist as abstractions for algorithms that will be used in the code. It is the most important design pattern engine in programming. You get a situation that repeats itself, or at least that is clearly a featured responsibility, and reuses whenever you need it without worrying about the details, and this is the best form of reuse that exists (it's not OOP as many think).

Function is the best mechanism for obtaining DRY. And the goal of jQuery is to decrease the repetition of tasks that everyone does in JS several times. You just parameterize what you want.

So the library does nothing revolutionary, it just gives you some ready patterns.

In fact, it is very simple. Perhaps the most sophisticated mechanism is to use anonymous functions to parameterize actions that must be performed within the jQuery function.

Obviously, the people who did it know how to program and can reuse code, compose everything they need efficiently as much as possible. Today it is very common to see codes out there that are repetitions and repetitions of things already existing in the very code that the person wrote, sometimes on the same day. This is not programming, it's just creating codes.

It's curious that adding jQuery and the person's code usually gets bigger than pure JS :) And gets much slower

a>.

    
21.11.2017 / 12:04