jQuery source learning note 1

Keywords: Javascript JQuery

Learning jQuery source code, I mainly learn from miaowi video. Here all the source code analysis, and some of their own understanding of the process of methods and examples collated out for your reference.
I use jquery v2.0.3.

var
   
   rootjQuery,

   readyList,

   core_strundefined = typeof undefined,

   location = window.location,
   document = window.document,
   docElem = document.documentElement,

   _jQuery = window.jQuery,

   _$ = window.$,

   class2type = {},

   core_deletedIds = [],

   core_version = "2.0.3",

   core_concat = core_deletedIds.concat,
   core_push = core_deletedIds.push,
   core_slice = core_deletedIds.slice,
   core_indexOf = core_deletedIds.indexOf,
   core_toString = class2type.toString,
   core_hasOwn = class2type.hasOwnProperty,
   core_trim = core_version.trim,

   jQuery = function( selector, context ) {
       // The jQuery object is actually just the init constructor 'enhanced'
       return new jQuery.fn.init( selector, context, rootjQuery );
   },

   core_pnum = /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,

   // Match non empty characters
   core_rnotwhite = /\S+/g,
   //Match HTML tags or IDS, such as < div > or "top"
   rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
   // Match empty labels similar to
   rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>|)$/,

   // Match -ms-
   rmsPrefix = /^-ms-/,
   // Match lowercase numbers with -
   rdashAlpha = /-([\da-z])/gi,

   // Convert string to uppercase
   fcamelCase = function( all, letter ) {
       return letter.toUpperCase();
   },

   // The ready event handler and self cleanup method
   completed = function() {
       document.removeEventListener( "DOMContentLoaded", completed, false );
       window.removeEventListener( "load", completed, false );
       jQuery.ready();
   };

Regular expression analysis:

rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,

Parsing: determine whether it is an HTML tag or an id, such as < div > or "top"
x|y means match x or Y
It can be divided into two parts to look at ^ (?: (s (< [\ w \ w] + >) [^ >] and ([\ W -]))$
1,^(?:\s(<[\w\W]+>)[^>]
?: (?: pattern) matches patterns but does not get matching results, that is to say, this is a non acquisition match and will not be stored for later use. For example, "industr y (?: y| ies)" is a simpler expression than "industry|industries".
\s matches any white space characters, including spaces, tabs, page breaks, and so on, zero or more times.
[\ w\W] + matches' [A-Za-z0-9] 'or [^ A-Za-z0-9]' once or more
(< [\ w \ w] + >) matched strings with < > included, such as < li >

2,#([\w-]*))$
Matches any character with a ා sign at the end, including underscores and-

rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>|)$/

\1 indicates that it matches the content in the first (). <p>< p > match, < li > < p > mismatch

Posted by reto on Fri, 13 Dec 2019 12:53:17 -0800