jquery Source Notes--Four

Source: Internet
Author: User

each () implementation
varJQuery =function(Selector, context) {return NewJQuery.fn.init (selector, context);}; Jquery.fn= Jquery.prototype ={selector:"", Init:function(selector) {//is still the mini selector.         varresult =Document.queryselectorall (selector);  for(vari = 0;i < result.length;i++){             This[I] =Result[i]} This. length =result.length; },    //specifies that the action object is thiseachfunction(callback) {returnJquery.each ( This, Callback)}, Constructor:jquery}jquery.fn.init.prototype=Jquery.fn//iterate over arbitrary objectsJquery.each =function(obj,callback) { for(vari = 0;i<obj.length;i++){        //use call to adjust the point of this        //the object in the callback function that points to the action        //Convenient OperationCallback.call (Obj[i],i,obj[i]); }    //Chained calls    returnobj}//TestJQuery ("div"). each (function(index, Element) {Console.log ( This)});//an array of iterations or other is often used internally by the JQ. Jquery.each ("Boolean number String Function Array Date RegExp Object Error". Split (""),function(i, name) {Console.log (Name.tolowercase ())});

Jquery.each is a tool for jquery, iterating over objects in the object collection, so it is not inherited in the prototype, and JQuery.fn.each is a special case of Jquery.each.

Each is a typical iterative application, such as a function that we want to perform on a collection of objects, and callback, through each object or array, can be used to implement callback objects that are constantly changing.

The principle is simple is to pass the element traversal to the callback function, in the original code also considered some situation, but nothing new knowledge, I do not add.

callback function

A function that is a parameter is called a callback function. When a function receives a function

jquery Source Notes--Four

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.