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