Articles published by Feng Xiaoxian

Recently submitted PR Comments by leaders LGTM A capital one It's in the brain. The abbreviations were checked and sorted out as follows:

  • PR: Pull Request. Pull requests, which have submitted code to open source projects, should all know
  • CR: Code Review. Code review
  • LGTM: Looks good to me. Yes, we can merge
  • TL;DR: Too long;Didn't read. The old woman's foot wrap.
  • TBR: To be reviewed. Give the labor review code!
  • WIP: Work in progress. Writing at the beginning of the title as an identification function is not completed
  • RFC: Request for comments. We usually hear that some policies want to be carried out. If the government wants to carry out these policies, the government will issue a draft for comments. The general meaning of open source projects is to ask for comments, which are used as task memoranda
  • ACK: Acknowledge. Confirm some contents, functions and tasks

Today, I went to visit my grandparents and played with my mobile phone. After playing with my mobile phone, my friend sent me a message: "is there any statement that can modify the folder path in batch?" so he asked about his needs. After half a minute's conversation, he found that it was dir/A => dir/2020/A According to the year corresponding to the excel table, classify the relevant catalog, and confirm that a few minutes is more than enough (too naive)

Since I didn't have a computer in hand and my mobile phone didn't have a proper editor, my friend suggested that he write it. I thought: OK.

Command is really difficult for people who have a programming foundation but can no longer reach their daily work. use readdirSync Listing all the directories under the directory has been operating for nearly half an hour, let alone debugging.

Calm down, I think, is it really necessary for ordinary people to learn? There is a certain need. If my friend simply grasps nodejs related skills, I believe that his work will be of great help. He does not need to manually copy and paste time-consuming, recognize the law of repetitive work, write scripts to execute the work, and efficiency will be his biggest experience.

After reading the above paragraph, it may mean "programming depends on work". I don't agree with this view. I agree with it Programming is a skill to improve productivity It can be understood in disguise as "Lazy" The friend mentioned above is just in the heavy processing of massive data, which is a little tricky. But if it's not related work, you can also use programming in other places to avoid being hit by the platform price difference when you buy your favorite items. You can master English indirectly and surf the Internet scientifically. Do not need to love, just because of interest and to understand, learn, meet the needs Happy, happy That's fine.

I saw it a few years ago "Python enters Shandong primary school textbooks" In retrospect, children's competitiveness has started since childhood. Cultivating thinking logic, observing children's interests and hobbies, and solving problems can be more logical.

In addition, programming should be regarded as a skill with the lowest threshold. After all, programs are everywhere in this era. Thanks to the open source sharing spirit of the Internet, relevant information can be readily available. The cost is really low, and learning is fruitful, You don't lose if you don't learn.

A strange bug was found in WSL today. Shouldn't sh be called directly under WSL

use Create React App Create a react application, yarn start Now, output Starting the development server... And then throw one Error: spawn cmd.exe ENOENT I wonder how this WSL is called to windows again cmd.exe It's weird. Hey

go create-react-app Turn it over Source code , executed an operation to open the browser and found that open Class library judgment windows Not just checking process.platform Yes, by the way wsl and docker The environment is also used as the judgment condition. The following splicing command is the final source of all evil

 root of all evils

Two ways to fix this bug

  1. take /mnt/c/Windows/System32 Add back the WSL environment variables so that you can pull up the default browser
  2. react-scripts/scripts/start.js Note it out openBrowser(url.localUrlForBrowser);

This is really an Indian bug, 🤮 The directory cannot be deleted

 rm: can't remove XXX: No such file or directory

After searching through the docker's documents and issues, this seems to be related to the ftype of the XFS partition. According to other people's solutions, it can't be solved 🤮 Yes

In the end, it's better to reduce two versions. Of course, it's OK to reload the system Dafa

Today, an old friend just chatted about jQuery source code. He didn't know the source code. I explained the core implementation to him with the attitude of learning and communication. (it seems that I have been pigeoning for a long time.)

By the way, which CDN service provider can find a jQuery file to open. I use version 1.2.3 as an example. The latest version is similar, with only two or three changes https://cdnjs.cloudflare.com/ajax/libs/jquery/1.2.3/jquery.js

Source code analysis

17-20 lines Pass in the selector and return the init method of its own new. I guess you haven't used it $() The second parameter is omitted here

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

Lines 26-27 This is why it always starts with $and is mounted under the window object, which is a global variable

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

Lines 36-547 Get rid of what we don't need, keep the core, stay init In this case, we ignore the internal method of jQuery

 JQuery. FN = jQuery. Prototype = {init: function (selector) {var nodes = document. Queryselectorall (selector); 
 for (VaR I in nodes) {this [i] = nodes [i]; 
} return this; 
} 
 / / omit 100000 words 
}}

549 lines In the previous paragraph, the jQuery prototype chain is passed to the init method prototype under the jQuery prototype. Looking back at the new code, it is very clear

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

Complete implementation

If you continue to add functions to the jQuery prototype, it will be very close to the original version of jQuery. Here I will simply implement it text() method

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

    jQuery.fn = jQuery.prototype = {
        init: function (selector) {
            var nodes = document.querySelectorAll(selector);
            for (var i in nodes) {
                this[i] = nodes[i];
            }
            return this;
        },
         element: function (callback) {
            for (var i = 0; i < this.length; i++) {
                callback(this[i]);
            }
        },
        text: function (content) {
            if (content == '' || content) {
                this.element(function (node) {
                    node.innerHTML = content;
                })
                 return content;
            } else {
                return this[0].innerHTML;
            }
        },
    }

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

    window.$ = jQuery;

end

In fact, the core is not complicated at all. I like the implementation of plug-ins. I think most of their functions are implemented by plug-ins. The ingenious design of the tool itself and the convenience.

In the traditional page production, jQuery is very comfortable to use, but the emergence of MVVM has changed our way of thinking. We only need to pay attention to business logic, do not need to manually operate DOM, and do not need to pay attention to the synchronization of data status. It is much easier for project management.

JQuery can only be used in a simple way.