How is jQuery built?

Asked

Viewed 108 times

0

As it is known, jQuery is an open source Javascript library whose intention is to facilitate the manipulation of DOM elements by abbreviating the code to be used to perform operations and procedures, where often in the so-called "pure Javascript"it would take more bytes of code and be more complicated to do.

As expressed in its slogan "write Less, do more", how does this library manage to cover all the complex Javascript language (functions, methods etc.) in "few" bytes (version 3.2 has about 84.6KB)? Which logic or system used in jQuery source code that "replaces" the native "pure Javascript" of the browser?

2 answers

5

how this library can span all the complex Javascript language (functions, methods etc.)

Simple, she doesn’t 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 are only utilitarian functions that make the bulk of the work within it and let you just pass the parameters, ie fill the gaps, which is exactly why we create functions.

Functions exist as abstractions for algorithms that will be used in the code. It is the mechanism of Pattern design most important of the programming. You take a situation that repeats itself, or at least is clearly a characterized responsibility, and reuse it 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).

The function is the best mechanism to get 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 doesn’t do anything revolutionary, it just gives you some ready-made patterns.

Actually it is very simple. Perhaps the most sophisticated mechanism is the use of anonymous functions to parameterize actions that must be executed within the jQuery function.

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

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

  • 2

    Neither covers the whole language nor replaces that there are infinite libraries "complementary" jQuery to do the service, such as dataTables, graphics, animations, responsiveness...

  • So I put "replace" in quotes because I found this information uncertain. :)

1


The jQuery has a engine DOM objects selection base. This engine returns the encapsulated objects in jQuery’s own objects.
These jQuery objects that encapsulate DOM objects are extensible and can handle DOM objects. In other words, you can create extensions to do basically anything.
Another great idea is to work well with the dynamism of javascript, passing whole objects as configurators and passing functions Anonimas as a form of function callback.
The issue of "do more, code Less" does not have much to do with the size of the file tá...(which incidentally, only has this size pq was compressed, the uncompressed version has more than 200) Is that they have done such a well-done job of encapsulation and extensibility, that with a single line you do things that before would be necessary 20, maybe even 100 lines of code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.