1.1 JQuery's Noconflict
1 var_jquery=window.jquery//window.jquery may be a variable name for another library, save it with a temporary variable in the JQuery object---var _jquery2_$=window.$//Ibid .3 Jquery.extend ({4Noconflict:function(deep) {5window.$=_$;6 if(deep) {//if jquery is required to give a global variable name in depth, the Noconflict function is passed to a parameter, and the global jquery is discarded as long as the argument displays true7Window.jquery=_jquery;//give back the value of the previous possession of the variable8 returnJQuery9 }Ten } One})
1.2 Object Extensions
1 functionMix (target,source) {2 varArgs=[].slice.call (arguments),//convert a Class Array object argument to a group3I=1, Key,4Ride=typeofARGS[ARGS.LENGTH-1] = = "Boolean"? Args.pop ():true;//typeof first determines whether it is a Boolean type, if it is the last parameter returned, if it is not true, the default is to overwrite the same name parameter5 if(args.length===1) {//The previous step has already overridden whether to overwrite the Boolean parameter with the same name, if only one argument is left6Target=! This. Window? This: {};//returns the this---the Window object if it is now under the global scope, or if it is not, returns an empty object to next accept the property of the remaining parameter7I=0;8 }9 while((source=args[i++])) {//Copy the remaining parameters to the target with a single attributeTen for(Keyinchsource) { One if(ride| |! (Keyinchtarget)) { Atarget[key]=Source[key]; - } - } the } - returnTarget; -}
1.3 Array
There are many class array objects in the browser function.arguments,doucument.forms,form.elements,doucument.links, and so on, some libraries have some array of functions
1 varMakearray =function(array) {2 varRET =[]; 3 if(array!=NULL){ 4 varI =array.length;//gets the length property in the array if the length property is empty, indicating that it is not an array of classes5 //The window,string,function has the Length property, string length, and function as the default number of arguments The array.setinterval determines whether the array is the Window object, although this is not the best way. 6 if(i==NULL||typeofarray=== "string" | | Jquery.isfunction (array) | |array.setinterval)7Ret[0]=array;//guaranteed to play is the array8 Else 9 while(i)Tenret[--i]=Array[i]; One } A returnret; -}
1.4 Type Judgment
The type function of jquery, which usually determines the type of a function by using the ToString function
1 class2type{}2 //It is possible to put several types of objects except the object into a Class2type object3Jquery.each ("Boolean number String Function Array Date regexpobject". Split (""), 4 function(i,name) {5class2type["[Object" +name+ "]"] =name.tolowercase ();6 });7Jquery.type=function(obj) {8 returnobj==NULL?//if obj==null because NULL does not have the ToString method, it calls the string function directly,9 String (obj):TenClass2type[tostring.call (obj)]| | "Object";//if the call to ToString returns the corresponding value for the object property written above, it is considered to be objec One}
1.5 Domready Implementation
WINDOW.READY=FN, this statement is the FN function that starts when all resources have been completed.
Use $ in jquery. (FN) can be used multiple times and will be executed sequentially, when the DOM tree is built.
There are four ways to determine if the DOM tree is complete
(1) There is a domcontentloaded event in the web, listening to this function execution function, now has many browsers support
(2) For IE can use Diego Perini hack
1(function (){2 Try{3Document.documentElement.doScroll (' left ');//If there is an error, the instructions have not been completed.4 } 5 Catch(e) {6SetTimeout (arguments.callee,50);//re-execute function after 50 milliseconds7 return;8 }9FireReady ();//the function to executeTen})();
(3) For IE can also use script defer hack to determine, but this is not recommended, to add a lot of script
1 document.write ("<script id=_ie_onload defer SRC=//0><\/SCR" + " Ipt> " 2 Script=document.getelementbyid ("_ie_onload" 3 script.onreadystatechange=function Span style= "color: #000000;" > () {//ie Even a dead chain can trigger an event 4 if (this . readystate== "complete" ) { 5 FireReady ();//Specifies that defer script will be triggered after the DOM tree is built 6 7 }
(4) for the firefox3.6 can be used to determine whether the document.documentelement is true before triggering, and similar to the second method above, not true continue to use the settimeout to iterate the call judgment
JavaScript reading essay 1