Articles under category JavaScript

Today, just an old friend chatted up the jQuery source code. He didn't understand the source code. I had a learning and communication attitude and explained the core realization to him. (as if he had been pigeon for a long time).

By the way, which CDN service provider is looking for a jQuery file to open? The 1.2.3 version I use here is for example. The latest version is almost the same, with only two or three changes. Https://

Source code analysis

17-20 elements Pass the selector and return the init method of your own new. It is estimated that you haven't used it either. $() The second parameter is omitted here.

 Var jQuery = window.jQuery = function (selector) {
return new jQuery.prototype.init (selector);}

26-27 elements This is why it is always a global variable to mount to a window object because of the beginning of $.

 / / Map the jQuery namespace to the '$' one
window.$= jQuery;

36-547 elements Eliminate the core of retention that we do not need. Init Method, the jQuery instance and the selector are judged internally. Here we ignore and simplify.

 JQuery.fn = jQuery.prototype = {
init: function (selector) {
var nodes = document.querySelectorAll (selector); 
for (VaR, 
for) = =; one hundred thousand;

549 elements In the last paragraph, the jQuery prototype chain is passed to the prototype of the init method under the jQuery prototype. Looking back at the new code, it is clear and clear.

 JQuery.prototype.init.prototype = jQuery.prototype;

Complete implementation

Adding functionality to the jQuery prototype is very close to the first version of jQuery. Here I am a simple implementation. Text () Method

 Var jQuery= function (selector) {
return new jQuery.fn.init (selector); 

jQuery.fn = jQuery.prototype = {
init:; (

jQuery.fn) = = (()); (0); (},}; (},}, "}", "}," "(") ";"


Actually, the core is not complicated. I like it very much. I think most of my functions are implemented by plug-ins. The ingenious design and convenience of the tools themselves.

On the traditional page production, jQuery used a very comfortable shuttle, but the appearance of MVVM changed the way of thinking. We only need to pay attention to business logic, do not need to manually operate DOM, do not need to pay attention to the synchronization of data status, and ease the project management.

If there are simple needs on a single page, jQuery is still useful, MVVM can only be added trouble.

Look at the new version Here

 Simple declaration wall implementation

Mobile phone adapter, computer access is not very friendly.

The inspiration for the wall is inspiration. Early summer I saw TA at the time. She? The wall was not very satisfied, so he thought he had made one.

The wall is a little bit like an ultra small micro-blog system. The database structure is not complicated. The table structure is as follows:

`id` int (5) NOT NULL AUTO_INCREMENT, \ "your name is \" (12), the name of ` s (12), IF, content, and IF, which is reserved. Now I do not know why.
  • Storage engine InnoDB Transaction processing can be supported. MyIsAM Can not Still use MyIsAM bar
  • Set up here IP It prevents children from spamming and limiting the number of confession. (you don't need to spend so much time in a period of time.
  • Utime The fields are temporarily useless, and later can be considered. Classification by time Check the corresponding expression.
  • I use it here. Mid The field is to separate each page from the white page (don't laugh at me), not URL. Id=1, id=2 bar
  • The character set of the table is Utf8mb4 (UTF dad died of paralysis? ) This can be supported. Emoji Expression Oh ~

Utf8 It only supports 1-3 bytes, almost 0000-ffff. and Utf8mb4 Supports 4 bytes and Compatible with utf8 So it supports more characters.

- reading the remainder part -