Jquery extend method (source code parsing), jqueryextend

Source: Internet
Author: User

Jquery extend method (source code parsing), jqueryextend

1. I have been busy studying data visualization (d3.js, three. js) and the laravel framework of php some time ago. I have encountered many things in my life. This is probably a time of confusion.

In retrospect, when I first came out to work, I had a very clear goal and wanted to learn something. What kind of height will be achieved in the future? We need to talk about things with the gods. Always toward this goal

Work hard. However, the more things you have seen, done, and done, the more you get confused. You may feel that you will not encounter any problems at work through du Niang.

But I can't think about anything. With your eyes closed, you can't remember it either. (maybe it's because of your age ). The goal has not changed, but it is confusing how you can become your idol.

Drifting and groping in the ocean at the front end alone, I know that there must be a lot of detours, but I also know that I keep moving forward. How can we find our own lamp without a beacon in our journey?

When I was bored, I read jQuery's source code, hoping to find my own lamp.

/** 1. $. extend usage. The first parameter determines whether deep replication is required. Set to true or false. By default, params: options => receives the intermediate parameters of the passed arguments. Name => no key value for the object. Src => when the key value of the passed object is the same. The value to be copied. CopyIsArray => judge whether the value object is an array. Clone => when performing deep replication. Create a variable. Does not change the original value. Target => at first, the default value is the first parameter passed in. Afterwards, I continue to jump. $. Extend (a, B, c); target is a, B, and c. I => determine whether the current target is equal to a value in the parameter length => deep => the default value is false, which determines whether deep replication is required. True indicates deep replication. False is a light copy */jQuery. extend = jQuery. fn. extend = function () {var options, name, src, copy, copyIsArray, clone, target = arguments [0] |{}, I = 1, length = arguments. length, deep = false; // judge the target to determine whether deep replication if (typeof target = "boolean") {deep = target; // when deep replication occurs, skip the first parameter. Parameters passed in cyclically. At the beginning, 1, 2, 3 target = arguments [I] | |{}; I ++ ;} // when the target is not an object and is not a function object, the target is changed to a null object. If (typeof target! = "Object "&&! JQuery. isFunction (target) {target ={};}// if only one passed parameter exists. Target is the parameter. If (I = length) {target = this; I --; // change I to 1} for (; I <length; I ++) {// handle non-empty or undefined cases. Null = null. Undefined = null; // options is used to receive all parameters except the first parameter. What is the function of the intermediate bridge? if (options = arguments [I])! = Null) {// name in options determines that the passed value must be an object. If it is not an object. To be split for (name in options) {// This determines the key value at the same level, and will be overwritten later. Src = target [name]; // obtain the value whose key value is name. Copy = options [name]; // Prevent never-ending loop prevents infinite loops. ??? If you do not understand it, it will happen only when you set it. If (target = copy) {continue;}/** 1. Perform recursive replication when the value is an object attribute. IsPlainObect (copy) determines that copy is not a pure object 2. copy is an array. Execute the functions. 3. (because only object values and array values need to be deeply copied .) */If (deep & copy & (jQuery. isPlainObject (copy) | (copyIsArray = Array. isArray (copy) {if (copyIsArray) {copyIsArray = false; clone = src & Array. isArray (src )? Src: [];} else {clone = src & jQuery. isPlainObject (src )? Src: {};}// create a new object. To perform deep replication. Target [name] = jQuery. extend (deep, clone, copy); // besides the object array and undefined values.} Else if (copy! = Undefined) {target [name] = copy ;}}// Return the modified object return target ;};

 

This section is from jquery. Version = 3.2.1. Each person's point of view must be different. I hope you can point out something wrong. Learn together.

The above Code does not come up with any idea.

// Prevent never-ending loop prevents infinite loops. ??? If you do not understand it, it will happen only when you set it. {}! = {} Does not come up with any situations in which target = copy will occur. If (target = copy) {continue ;}

At present, I have read about 1 in 10 and learned a lot of routines. Maybe you can find your lamp.

Another wish: the handsome guys are getting more handsome and beautiful. Pai_^

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.