JavaScript-Little Kee

Source: Internet
Author: User
Tags array sort static class

JS Introduction mode:  1, embedded mode  2, outer chain way   js realize slide (picture play) Common variable name: 1, Hump 2, Pascal: Capital of each word 3, Hungary: Attribute + Type + Object Description     ,g_str_w3c window: 1. alert  2. confirm3. prompt Data type:1.  The original data type is stored in the stack, and the variable and its value are stored in a single undefined, null, number, string, boolean2.  reference data type-composite data type typeof --  View data type condition control: If, switch (support string), ternary operation, loop control:whiledo...whileforfor...in   generally use  &nbsp in arrays or objects; A direct traversal of the result is an index to an array or a property name in an object Breakcontinue class and object: The JavaScript class itself is also an object. Custom objects: Var obj = {name: ' Tom ',age:2} ; or Var obj = new object (); obj.name  =  ' Tom '; if (obj.name) {...} Or if ("name"  in obj) {...} Property gets: 1, using the dot operator   obj.name2, using brackets []   obj["name"]    ---  Can be used for complex key problem static class://This form is called the direct amount of the object var person = {  name: ' Jerry ',  age:2} ; Non-static class: Var car = function (Name,color) {this.name = name ;this.color =  color ;this.say = function () {alert (this.name);//  here refers to the current object function (the function is also an object), that is, to the say ,//  But found that there is no name in the say attribute, so go to his father to find the name, if found to use (this will represent the object with this property), or continue up a layer of the father to find, know the topmost, if not undefined};} Note that the non-static class needs to be instantiated (with the new operator) to access its internal properties Var car = new car (' BMW ', ' red '); with keyword:    ---  minimize use, easy to waste system resources with (obj) {alert (name);} This: Represents the current object, for more complex objects or calls, how to distinguish this exactly represents who  --   who called (the method) then this represents who. Prototype:var car = function () {};//  by prototype into the public properties car.prototype.name =  ' BMW '; car.prototype.color =  ' Red '; Car.prototype.say = function () {}; Class attribute: Car.run = function () {}; Class methods: Object Properties: Object methods: Common built-in objects in JavaScript: 1, stringvar str = new string (' Hello world ');  //  new  Way var  str =  "Hello world"  ;  //  Common properties and methods for object Direct Volume: Global Method:  parseint parsefloat str.lengthstr.charat (1);  // Returns the specified index-out character str.charcodeat (2);//Returns the ASCII encoding of the character at the specified indexR.concat (' Hello ', ' wor ', ' world ')  ; //  link string str.indexof (' World '); //  Returns the first occurrence of the world's position str.lastindexof (' hello '); Str.replace (' World ', ' Heiheiru ');//regular use with regular  : str.replace (/o/ G, ' P ');  globally replaces all Ostr.slice (2,6); Str.split (' # '); Str.substr (2,5) str.substring (); " HELLO ". toLowerCase (); Str.touppercase () str.tostring (); Str.match (regex)  ; //  An array that returns all the results of a regular match can use prototype to append additional methods to string. 2, Datevar date = new date ()  ;  //  return current DateTime method: GetDate ()  ; //   return  0-31 getday ()  ; //  return one day of the Week  0 -6 getmonth (); //  0-11 getfullyear ()  ;//  return four-bit year   , getyear ()   deprecated gethours ()  ; //  0-23 getminutes (); getseconds ();  // getmilliseconds ()  ;//gettime ();  // Returns the number of milliseconds date.parse (dateval)  ; //  returns 1970 to the specified time from 1970 to now toTimeString ()  ; //  Converts the time portion of a Date object to a string todatestring ()  ; // Converts a Date object part to a string setdate ()  ;//  sets a day of the month in the date (1-31) setmonth ()  ;// 0-11setfullyear ()  ;//   Four-digit sethours ()  ; // 0-23setminutes ()  ;// 0-59 settime ();//  Use the number of milliseconds to set the time 3, Number attribute:max_value , Min_value, nan , negative_infinity  negative infinity, positive_infinity positive Infinity Method: ToString ()  ;tofixed (0-20)  :   parameter specifies how many decimal digits are reserved for a number 4, array property: length , prototypevar arr =  new array (1,2,3,4, "a", "Hello", {x:1,y:3}); //  can put complex types of data, the type does not have to be consistent var arr =  [1,2,3,4, "a", "Hello",{x:1,y:3}] ; //  object direct Volume definition way concat ()  ; //  concatenate different arrays, Put multiple array contents into an array var arr1 = [1, 2, 3, 4];var arr2 = [' a ',  ' B ',   ' C '] ;arr1.concat (ARR2);   //     join ()  ; // Returns the element in the array by connecting it with the specified argument. Arr1.tostring ()  // tostring by default uses commas to concatenate array elements and returns POP ()  ; //  returns and deletes the last element in the array push ();  // Add one or more elements to the end of the array, and returns the new array length. Empties the array arr = [] ; or   arr.push (); Unshift ()  ; //adds one or more elements to the head of the array reverse ()  ;  //  Invert array element shift ()  ; //  Delete array first element slice (); splice (Index,howmany[,elem]); //  Delete howmany elements from index, and add elements to the deleted element at sort ()  //  sort  , there are many sorting algorithms sort (); //  no parameters, the array sort first, ... Sort (function (a,c) {if (a > b) {return 1}else{return  -1})  ; //  Custom sorting algorithm sort (function () {renturn a-b})  //  sort from small to large (function () {renturn b-a})  //  From the large to the small sort custom algorithm can use the number axis to represent:  -num  ——————————————— 0 —————————————————————  +num returns negative, the position of the two elements is swapped, Returns a positive number does not change, if is 0 also does not Exchange 5, the Math attribute:      e, LN2, LN10, PI, sqrt2  and so on method:  abs (x)  ;    Absolute  ceil (x)  ; //  rounding up   1.1 - 2  , 1.000 - " 2 floor (x)  ; //  rounded down  round (x)  ; //  rounded  exp (x);  // Index of  e &nbsP;max (x, y, z,....); /Return to X Y ,Z  The largest value in  min (x, y, z,...)  pow (x, y),  // x  random ()  ;//  random number between 0 - 1   6, function Properties:arguments   , Arguments.length (method overloads for other languages are simulated using the number of arguments) (function (i) {alert (i); Arguments.callee (++i);}) (0); method: Arguments.callee () uses function object to define functions &nbsp, and the last parameter as function body var abc = new function (' A ', ' C ', ' C ', "alert (a+b+c);"); ABC (); 7, Global8, windowdom  -  Document Object Model automatically constructs a Window object whenever the browser opens a Windows. dom |  window     | | ---------------------------------------------------------||             |             |               | Navigator       screen       history        &nbSp Method of Location        documentwindow:  settimeout ();  Cleartimeout ();  setinterval ();  clearinterval ();     navigator :  Mainly contains the client browser information to determine the browser type and version information cookieenabled ---  Determine whether cookies enable useragent --   browser information, A string's match method is generally used to filter the required property information screen : Contains client screen information height, width, avaiheight, avaiwidth     history:  Browser Current Window history length  --  history length back (); forward (); Go (-/+num);location:  Contains information about the current URL hash //  settings or returns a URL anchor (such as  :  #course2) href //  set or return urlhostname //   Sets or returns the current hostname pathname //  setting or returns the path portion of the current URL protocol //  set or return protocol search //  Sets or returns a query string (containing a question mark)   (does not contain an anchor part) assign ()  //  load New Document reload ()  //  reload replace ()  // New document replaces the current document DOM node operation:  operation of the HTML document Access node through the Document object: getElementById (); Getelementsbyname (); //  Returns the array form getElementsByTagName (); //  returns the array creation node: createelement(); Creattextnode (); Add node: appendchild (node)  ;insertbefore (newnode,oldnode); Delete node: removechild (node); Get parent node: parentnode ; Replacement node: ReplaceNode (Newnode,oldnode); Use document fragmentation to improve JS execution efficiency  :   write JS to minimize the operation of the DOM, You can do this one operation at a time, reducing the DOM element's lookup by doing more. Createdocumentfragment () Table operation: Caption :createcaption ();d eletecaption (); Thead:createthead ();d eletethead (); Tfoot:createtfoot ();d eletetfoot (), Tbody:rows insertrow ();d eleterow (); Cell:insertcell ();d Eletecell ();D Attributes of the OM element: SetAttribute (Name,value),     getattribute (name), RemoveAttribute (name), common as style  ,style.cssText    innerText ;innerHtml ;outerText;outerHtml ; Events   : HTML event onload (); onresize (); onscroll (); keyboard mouse event onclick (); Ondbclick (); onmousedown (); onmouseover (); onkeypress (); O Nkeydown (); onkeyup (); form event onfocus (); onblur (); onchange (); OnReset (); onsubmit (); The property or method of the event object button -   identifies the left and right three keys of the mouse ctrlkey altkeyshiftkeytypetarget srcelementscreenx/ Screenypreventdefault () stoppropagation () &nbSP;;  //  Block event bubbling    different browsers have distinct event stream capture events (from outside to inside of the lookup process) bubbling events (from the Inside out) such as common assignment events  :  document.getElementById (' btnsubmit '). Onclick = function () {} ; The binding of an event can be overridden (the order in which the same event is bound) not all events can bubble. The following events do not bubble: blur, Focus, load, unload//block event bubbling function function stopbubble (e) {if  (e &&  e.stoppropagation) e.stoppropagation () Elsewindow.event.cancelbubble=true} event handling and listener function AddEventListener (EventName, Callback,isbublepop); //  The third parameter specifies whether it is a bubbling or capturing event RemoveEventListener (); attachevent ();d etachevent (); Cookie :cookie capacity does not exceed 4k  add:document.cookie =  "value"  ;  multiple cookie values using a semicolon-separated space


JavaScript-Little Kee

Related Article

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.