JQuery in my eyes

web front end six thousand and seventy-four 14 years ago (2011-03-21)

Like me, you should have a deep feeling about jQuery, a lightweight js framework, because it makes our work easier and makes the code structure clearer. However, it also has a negative impact. If you use more, your own js ability may decline, which also varies from person to person.

In order to enhance my understanding of jQuery and experience the master John Resig's code style. Today I have a good look at the source code of jQuery.

In fact, the overall architecture of jQuery is quite simple. The most basic code is as follows:

 (function() { var myQuery = (function() { var myQuery = function(args) { alert(args); }; return myQuery; })(); window.myQuery = window.$ = myQuery; })(); $(88);

The above code is a clear organizational form that I rewrite myself according to the source code of jQuery.

First, define a namespace, declare a function in the namespace, and return a function pointer inside the function. In fact, this pointer is the real object to be used. Later, all jQueries extend methods on this object.

Js code:
 window.myQuery = window.$ = myQuery;
 window.myQuery = window.$ = myQuery;

The above method is to make the $in the global variable point to the object pointer.