JS Advanced Programming--notes

Source: Internet
Author: User

1, JS three parts: ECMAScript, Dom, BOM 1) ECMAScript: Provide core language features 2) DOM: Provides methods and interfaces for accessing and manipulating Web page content 3) BOM: Provides methods and interfaces for interacting with browsers 2. Write JS on HTML page Code that needs to put the code in <script></script>; and cannot appear in the middle of the string "</script>" below this code will error:alert ("</script>");      It can be escaped: alert ("<\/script>"), 3, if you reference an external JS file, the JS code within the tag will be ignored 4, JS six data types: Undefined, Null, Boolean, number, String , object can use the TypeOf operator to detect the variable type;--if the value is NULL, return "Object"//null is considered an empty object reference--if it is a function, return "function"--the variable is a declaration or a sound Undefined 5, undefined derived from null, so undefined = = NULL,//TRUE6, using the function Boolean (), any type of value can be converted to a Boolean type; empty string, 0, Na N, null, undefined is false, other values are true;7, number type representation: decimal, octal, hexadecimal--eight binary: starting with 0, var num1 = 070; Corresponds to decimal 56--16 binary: Start with 0x, var num2 = 0xA; Corresponds to a decimal 10extension: JS floating-point number is based on the IEEE754 64-bit standard (binary floating point standard);caused by bug:0.1 + 0.2! = 0.38, 0/0 = NaN;    1/0 = infinity;  -1/0 =-infinity;9, parseint ()   can parse: decimal, hexadecimal string;      parsefloat ()   can only parse decimal string 10, For a negative binary representation        1) First get positive binary;        2) get the inverse code, i.e. 0 and 1 interchange         3) + 111, switch when comparing values is congruent, 12, the function of passing parameters, if it is a reference type, is also passed by value.         function setName (obj) {           obj.name = "LLM";           obj = new Object ();           obj = "LLM1";       }       var person = new Object ();       setname (person);    &nbs P  alert (Person.name);  //llm      can be understood as it is a partial reference pass 13, garbage collection algorithm         1) Mark Clear (current mainstream): Tag variables (enter the environment, leave the environment), The garbage collector then recycles these variables at regular intervals         2) reference counting (not commonly used) causes the problem of circular references, which results in the memory not being purged; 14, the execution environment is divided into: Global execution environment and function execution Environment 15, Two ways to create objects     &nbsp  1) var person = new Object ();       2)   var person = {};16, two ways to access the object       & nbsp;1) via ' point ' access:  person.name       2) via square brackets  : person["name"]    // Its advantage is that you can use variables to get the properties of an object person[variable]17, to determine which type of instance an object belongs to, and you can use your own method by instanceof;        Judging the array: Array.isarray (value), 18, Stack: LIFO         queue: FIFO 19, array method:         --push () & nbsp Append data to the end of the array and return the changed array length        --pop ()     Move the value at the end of the divisor and return the result      --shift ()   Remove the value of the first item      --unshift ()   Insert value at start of array      --reverse ()   Inverse array     & nbsp --sort ()   default by string rules for ascending sort                       You can pass a comparison function to determine Which value precedes, 20, Date object related methods        --gettime ()   The total number of milliseconds to get the date; same as valueof ()        - -getfullyear ()   get four-digit year     &NBSP  --getmonth ()   Get month, starting from 0        --getdate ()   Get days        --getday ()   Get the day of the week, 0 weeks   6 weeks six        --gethours ()   Get hours        --getminu TES ()   Get minutes        --getseconds ()   Get seconds        --getmilliseconds () Get the number of milliseconds 21, RegExp type: Regular expression         var expression =/pattern/flags;       --patte RN indicates regular expressions        --flags to indicate matching flags: g, I, M, can be combined using;           1) G   Global search;             2) I   means ignoring case,            3) m   table The  22, function type           functions are actually objects, whereas the functions are simply pointers to objects;         var Hello = function () {};          So there is no overload; If you define multiple identical functions, JS resolves from top to bottom, so the final function name points to the last function, 23, two ways to define the function:        1, function declaration: Function Hello () {}       2, function expressions   var hello  = function () {};        the difference between the two:1) The parser makes a declaration of the function declaration in advance of the process, that is, regardless of where the function is defined, can be pre-used 2) and function expression, only execution to the current code line, will be parsed execution;Basic Package Type: String, Boolean, number; it is a special type of reference although they are three primitive types, the base type does not belong to the object, so there should be no methods and properties; But we know that there are many methods of string, such as substring ();        It? var str = ' 123123123 ';var str1 = str.substring (2);This line of code, the background did three operations1) Create an instance of string type var str = new string (' 123123123 ');2) Call the method of this instance str.substring (2);        3) Destroy this instance         &NBSP;STR = null; 25. The difference between the basic packing type and the reference type: Life cycle;       --life cycle of reference types: existing        --basic wrapper types before leaving the current scope: The execution of a single line of code, the difference between 26, encodeURI () and encodeURIComponent ()        1) encodeURI to colons, forward slashes, #不会进行编码        2) encodeURIComponent Colon, forward slash, #等特殊符号进行编码, 27, eval () method is equivalent to a complete ECMAScript parser, it can parse the JS code string;       -NOTE: In strict mode, the variables defined in eval () are not accessible externally; 28, Factory mode: Batch creation of similar objects         function Createperson ( Name) {    var obj = new Object ();  obj.name = name;  return obj;       }29, constructor mode: Call function via new         function person (name) {this.name = name;}         var person = new Person (); 30, prototype mode         The creation of each function has a property prototype point to an object, this object Contains the properties and methods shared by all instances; 31, hasOwnProperty ()   can determine whether the property belongs to an instance of        --true represents a 32, in operator   You can tell if an instance contains a property, whether it exists on an instance or on a prototype 33, each function has a prototype property that points to an object that contains properties and methods shared by all instances;       function person () {};         person.protype.name = ' haha ';       person.prototype This property will contain the properties and methods shared by all instances;             var llm = new Person ();         alert (llm.name);  //haha            Each instance has an attribute [__proto__], which points to the prototype object;     alert (ll M.__proto__.name);  //haha34, prototype object problems:        1, created instances have fixed attribute values;        2, if the attribute values in the prototype are reference types, By modifying the values in one instance, the other instances change;        ——————————         Solutions: Combined using constructors and prototype patterns;         1) Constructors: defining instance properties         2) prototype mode: Properties for defining methods and shares;        Fun ction person (name) {this.name = name;}         Person.prototype.sayName = function () {alert (this.name);}                  _________________________         The above method has solved the problem very well. But it's not elegant.;          Dynamic prototype mode writes prototype mode in the constructor          function person (name) & nbsp      {          this.name = name;          if (typeof this . sayname! = "function") {           //If this method does not exist, create           &NBS P Person.prototype.sayName = function () {alert (this.name);};          }       } 33, Arguments.callee   represents a pointer to a function being executed;   Strict mode Error;       function factorial (num) {         return num * Arguments.callee ( num-1);     }34, modify window.location.href     values, automatically call the Location.assign () method, generate history;        Location.replace ()   does not generate a history; 35, scrollIntoView ()   This method is called on the element, and the scrollbar is scrolled to it;        var div = document.getElementById (' diV1 ');          Div.scrollintoview ();

JS Advanced Programming--notes

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.