The first chapter of the JavaScript Advanced Program Design notes-----

Source: Internet
Author: User
Tags cdata time zones

Chapter I.

JavaScript consists of ECMAScript, DOM, and BOM. Among them, the BOM function has the formal specification in the HTML5, makes the BOM compatibility more and more high.

Chapter II

1. The async attribute in the <script> attribute indicates that the version should be downloaded immediately but should not interfere with other actions on the page, only valid for external files, async= "Async". The Type property defaults to Text/javascript. Defer property

It is possible to delay the document being fully parsed and realistic, only valid for external files, defer= "defer".

2, embedded in JavaScript in <script>, you can no longer use </script> anywhere else, or it will be considered as the end flag, if you want to use, you should add the escape symbol in front \

3, <script> Reference when using <script/> does not conform to the HTML specification, and can not get some browsers, especially the correct resolution of IE, so use <script></script>

4, XHTML code specification is more stringent than HTML, such as a < B, can be parsed in HTML, but in XHTML < cannot be followed by spaces, so you can use CDATA fragments, put the comparison in the

<! [cdata[

Code Snippets

]]>

5, when the browser does not support script or browser support script, but when the script is disabled, if there is <noscript>, will be executed inside the content

Chapter III

1, variables, functions and operators are case-sensitive, the first letter must be a letter, _, $

2, Strict mode: "Use strict", the entire script is enabled, put on the top, before the specified function, the strict mode is placed in a function. In this mode, the function cannot be defined, the name of the parameter is eval and arguments, otherwise it causes a syntax error

3, data types include: underfined, Null, Boolean, number, string,typeof can return data type, undefined variable by default to get underfined value, non-numeric conversion to a value can use numbers () [ Applies to any data type, null character returns 0], parsefloat () [Applies to String, 22.5->22.5], parseint () [applies to String, null character returns Nan, decimal point is not a valid numeric character, 22.5->22]

4. For-in Statement: for (property in expression) {code block}

5. Label statement (tag code): Label:statement For example: Start:for (var i = 0;i<count;i++) {code block}

Fourth Chapter

1, only reference type values can be added to the property, when copying the value of the variable, the new variable is affected by the variable, the base type value cannot add attributes, when copying the value of the variable, the new variable and variable are independent of each other

2, the detection reference type uses instanceof, for example: Person instanceof Object

Fifth Chapter

1. How to create an object instance:

(1) The constructor of the object after the first new

var person = new Object (); -----Law II: var person = {};

Person.name= "AA";

person.age=23;

(2) Object literals, attributes can also use strings, attributes are automatically converted to strings if they use numeric values

var person = {

Name: "AA",

Age:23

}

2, DisplayInfo ({name: "AA", age:23})

function DisplayInfo (args) {}

3, (1) var color = new Array (), the parentheses can be passed the value of the string can also be passed, where new can be omitted

(2) array literal: var color = [];

4. Add a new entry at the end of the array: color[color.length] = "red";

5. Detect array: (1) if (value instanceof Array) {Perform certain actions on array}

(2) if (Array.isarray (value)) {Some operations are performed on an array}

6. In the array:

1) toString () can convert each worthwhile string to a comma-delimited string,

2) valueOf () can be returned or array

3) Join () Add delimiter

4) push () can receive any number of parameters, pop () gets the value of the last item

Shift () Gets the value of the first item, Unshift () can add any item to the front of the array and return the length of the new array

5) Reorder: sort () ascending \ Reverse () descending

6) Concat (); You can create a copy of the original array and then add the accepted parameters to the end of the copy. Cases:

var color = ["Blue", "Red"];

var color2=color.concat ("yellow");//blue,red, Yellow

7) Slice () can create a new array based on one or more items in the current array. Example: Slice (1) copying starting from position 1, slice (2,4) copying from position 2 to end 3, slice ( -2,-1) starting from position 2 copying

8) Splice () inserts an array into the middle of the array, (1) Delete: Splice (0,2) deletes the first two items of the array

(2) Insert: Splice (2,0, "Red", "blue") inserts a string from the current array position 2

(3) Replace: Splice (2,1, "Red", "blue") removes the entry for array position 2, and then inserts the string starting at position 2

9) Location Method: (ie9+, Firefox, Safari, Opera 9.5+, Chrome)

IndexOf (); Find from the start

LastIndexOf (); Start at the end of the search

10) Iterative method: Every (), some (), filter (), map (), ForEach ()

11) Merge Method: Reduce (); Reduceright from beginning to end (); from tail to head

7. Date

1) var date = new Date (Date.parse ("May 21 2016"));

var date = new Date (DATE.UTC (2016,2,21,17,31,55));

2) todatestring (); Show Day of the week, month, date, year

toTimeString (); show hours, minutes, and time zones

Tolocaldatestring (); Displays day of week, month, date and year in a region-specific format

Tolocaltimestring (); Display time, seconds, and time zones in an implementation-specific format

toUTCString (); Full UTC date in implementation-specific format

8. Regular expression: (RegExp ())

1) G: Global mode I: Case insensitive M: Multiline mode

Need to escape the meta-symbol: ([{\^$|)? *+.}

2) Global: Whether the G flag is set

IgnoreCase: Whether the I flag is set

LastIndex: Indicates the character position at which to start searching for the next occurrence, starting from 0

Multiline: Whether the M flag is set

Source: The string representation of a regular expression

3) EXEC () Capture group with two additional attributes: Index and input

4) The constructor property of the regular expression:

Input ($_): The most recent string to match

Lastmatch ($&): Last Occurrence

Lastparen ($+): Last matched capture group

Leftcontext ($ '): Text before lastmatch in the input string

Multiline ($*): Boolean, Multiline mode

Rightcontext ($ '): Text after lastmatch in the input string

PS: When using short attributes, remember to add [], for example: ["$+"]

Opera does not support: input, Lastmatch, Lastparen, multiline

IE does not support: multiline

Not to be continued ...

The first chapter of the JavaScript Advanced Program Design 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.