JavaScript authoritative Guide notes-part 1th

Source: Internet
Author: User
Tags bitwise modifier

# The JavaScript authoritative guide notes-part 1th
Description: Printed version: April 2012 1th Edition, September 2016, 17th time printing.
The style of the book and "effective Java" very similar, recommended.
This note is recorded in reverse order.


-----------------------
------<end>------
| Node's HelloWorld program: "' js//! program.js//runs by typing ' node program.js ' on the command line and then opens the URL ' 127.0.0.1:8080 ' in the browser to access var http = require (' http ');
var server = new http.  Server (); Server.listen (8080); Server.on (' Request ', function (request, response) {Console.log (Request.url);//Print Request URL  Response.Write ("Hello world!"); Response.End ();});
```
| Rhino, a JavaScript interpreter written in Java. In the [Mozilla/rhino:rhino is a open-source implementation of JavaScript written entirely in Java] (Https://github.com/mozill A/rhino) in specific studies.
| JavaScript Runtime Environment (in addition to two operating environments except web browsers)-[download Rhino-mozilla products and Proprietary Technologies | MDN] (Https://developer.mozilla.org/zh-CN/docs/Mozilla/Projects/Rhino/Download_Rhino)-node:https://nodejs.org
# # 12th: Server-side JavaScript
| The array to the right of the deconstructed assignment does not have to correspond to the variable one by one on the left, the assignment of the extra variable on the left is ' undefined ', and the value on the right is ignored. The list of variables on the left can contain contiguous commas to skip the corresponding values on the right. --p275 "Jslet [x, Y] = [1]; x = 1, y = undefined ""
| Variables declared through Var are available within the function, while variables declared by let are only part of the nearest curly braces. --p272
# # 11th: Subsets and extensions of JavaScript
| RegExp Method-' EXEC () ': the Exec () method executes a regular expression on a specified string. The Lastindex property will function after setting the ' G ' modifier. --p264--p265-' Test (String) ': detects a string and returns True if it contains a match;
| The string supports 4 regular expression usages. --p262-string.search (/Regular/); If the parameter is not regular, the regular object is constructed through RegExp;-string.replace (/Regular/, "text to be replaced"); If the first argument is a string, the string is searched directly instead of being constructed as a regular expression. The second argument can be a function that dynamically computes the replacement string;-String.match (/regular/); The most commonly used regular method;-String.Split (/regular/); The argument can be either a string or a regular;

| Regular expression modifier: a character that appears outside the second slash. --p261 ' I case-insensitive G global match m multi-line pattern matching '
| Anchor character:--p261 "^ Match string beginning $ match string end \b Match word boundary \b Match non word boundary (? =p) 0 Wide forward assertion, requires next character to match P (?! P) 0 Wide negative forward assertion, requiring the next character not to match P '
| Non-greedy matches (match as few as possible): follow a question mark in the matched word specifier. --p257
| Repeat:--p257 ' {n, M} (at least n times, not more than m) {N,} (matches the previous item n times to several times) {n} matches the previous n times? 0 or more times + 1 or more times * 0 or more times '
| Character class: The character class is composed of a direct measure character placed in square brackets ' [] '. --p256
| In regular expressions, punctuation that has a special meaning:--p255 ' js^ $. * + ? = ! : | \ / ( ) [ ] { }```
| The ECMAScript 5 specification does the opposite of ECMAScript 3, which returns a new object for each operation of the direct amount of the regular expression represented by the same piece of code. --p254
| Create regular Expressions:-Use the ' RegExp () ' constructor to create;-use regular expression direct-amount syntax (characters that are contained between a pair of slashes);
# # Tenth: Regular expressions

| module, export api:1. Returns the constructor function;--p2512. Call the module function directly via new;--p2523. The Export module API method provided by the framework;--p252
| Modularity to implement code reuse. --p248
|  Lock a use case for a prototype object: Prevents changes (modification and deletion) of the enumeration type ' enumeration () ' property. The settings that were made before the ' Object.freeze () ' method call are active. --p244
| The functions of ' object.freeze () ' and ' Object.seal ' will set the object's properties to read-only and not configurable. --p244 Note: There is no anti-action;> freezing an object is the ultimate form of lock-down. Once an object have been frozen it cannot be unfrozen–nor can it is tampered in any manner. The best-of-a-do sure that your objects would stay exactly as you-left them, indefinitely-[opposite of Object. Freeze or Object.seal in JavaScript] (http://stackoverflow.com/questions/19293321/ Opposite-of-object-freeze-or-object-seal-in-javascript)
| ' Object.defineproperty () ' and ' object.defineproperties () ' can be used to create new features or to modify properties of existing attributes. --p242
| ECMAScript 5 adds restrictions to the extensibility of the object (method support: Setter, getter, enumerable, writable, configurable), and its new features make the class more robust. --p239 "Jsobject.defineproperty (); Object.defineproperties (); Object.seal (); Object.preventextensions (); O Bject.create (); Object.freeze (); Object.getownpropertydescriptor ();

| ' var str = json.stringify (o); ' Convert the object to a JSON string, ' Json.parse (str) ', convert the string to an object, but the object does not have the same inheritance structure as the O object. --p222
|  Duck type can not be applied to built-in classes, such as the ' Quacks (o, Array) ' to detect whether O implements the Array of all the same name method. The reason is that the methods of the built-in classes are non-enumerable (For/in operations cannot traverse). --p217
| In JavaScript, the implementation of a class is based on its prototype inheritance mechanism. --p201
# # Nineth: Classes and modules
| You need to pass a parameter to ' F () ', so use the ' call () ' method of ' F () ', need to pass multiple arguments to ' g () ', so use ' apply () ' Method of ' g () ';--p197--p189 ' ' Jsfunction f (a) {  Console.log ("a=" + A)}function g () {Console.log ("args:" +arguments.length)}f.call (this, 3); = = A=3g.apply (this, [3, 1, 4, 1, 5, 9, 2, 6]); = "Args:8"

| Functions can be defined in the same way as the ' new function () ' constructor (two other definitions: 1. function definition statement; 2. Function Direct amount expression). The ' function ' constructor creates an anonymous function that does not need to specify a function name. --p192
| One thing to keep in mind when writing closures is that this is a keyword for JavaScript, not a variable.
| The execution of a function depends on the scope of the variable, which is determined when the function is defined, not when the function is called. --p182
| Call the anonymous function directly "JS" (function () {Console.log ("I am an anonymous function, I am called")} ());(function (x) {Console.log ("I am an anonymous function, I am called = =" + x)}) (3); ' Note: The left parenthesis before ' function ' is required, and if you do not write the left parenthesis, the JavaScript interpreter will parse the keyword function into a functional definition expression.
|  Call the function in the function: "' js//function in function A () {Console.log (" I am a "); return b;}
Function B () {Console.log ("I am B"); return c;}
Function C () {Console.log ("I am C");}
A () () (); = = I'm a/n, I'm b/n, I'm C ' '
| ' Arguments[' object: The function contains a fixed number of named and required arguments, as well as an optional argument with a subsequent number of variables. --p175
| JavaScript default check behavior for arguments: The omitted arguments are ' undefined ', and the extra participants are automatically omitted. --p174
| The identifier ' arguments ' is a reference to the argument object, which is a class array object.  You can access the incoming argument values by using the subscript. For example: ' Argeuments[0] ' represents the first argument, ' Arguments.length () ' indicates the length of the real parameter group. --p174
| This is a keyword, not a variable, or a property name. The syntax of JavaScript is not allowed to assign a value to this. --p171
| Any function will actually pass in an implicit argument as a method call-the argument is an object, and the parent of the method call is the object. --p170
| function definition expression/Function declaration statement-Function declaration statement: The ECMAScript specification simply allows them to be the top-level statement. Can appear in the global code, or embedded in other functions, cannot appear in loops, conditional judgments, or try/catch/finally. -function definition expression: can appear anywhere in the JavaScript code. --p168
# Chapter Eighth: Functions
| For the string ' var a = ' test ' Although the character can be obtained by ' a[0 ' (very similar to how the array is obtained), but the string is not an array: ' Array.isarray (a) = = = False '.
| ' Array.indexof () ' and ' Array.lastindexof () ':-Parameter 1: the value to be searched. -Parameter 2: Specify an index in the array from which to start the search. (optional, if omitted, searches from the beginning; if negative, the relative end offset)--p160
| ' Array.reduce () ' requires two parameters:--p158-parameter 1: The function that performs the simplification operation. -Parameter 2: The initial value passed to the function (optional). ' Jsvar a = [1, ' A ', ' B ', ' C ', 3, 3, 88];a.reduce (function (x, y) {return x+y;}, 1); = "2abc3388"
| foreach cannot terminate traversal before all elements are passed to the called function. Can be interrupted by throwing out an exception. --p156
| [The difference between functions and methods in JavaScript] (http://www.cnblogs.com/moltboy/archive/2013/04/24/3040450.html) function: A block of executable JavaScript code, Predefined by JavaScript program definitions or JavaScript implementations. Method: is a JavaScript function that is called through an object. (a method is nothing more than a JavaScript function that is stored in an object's properties.)  --p169) (If the function is mounted on an object, as a property of an object, it is called a method of the object.) When the function is called through this object, the object is the context of the call, that is, the function's this value--p165) method is used to manipulate the This object, the This object is an important property of the method, when the This object appears inside the method body, This value points to the object that called the method. Functions are usually independent and do not need to use the This object frequently.
| ' Array.push (a) ' and ' Array.pop () ', both modify the original array itself. --p154
| ' Array.splice () ', modify the element itself. -Parameter 1: Specify the starting position of the insertion or deletion;-Parameter 2: Specifies the number of elements that should be removed from the array. (no element is removed at 0)-subsequent parameters: the element to be inserted; "' Jsvar a = [1, 2, 3];a.splice (1, 1, ' A ', ' B ', ' C ')//= = [2]a//= = [1," A "," B "," C ", 3 ]```
| ' Array.concat () ' does not recursively flatten an array of arrays. ' Concat () ' Also does not modify the called array.
| ' Array.reverse () ' operates on the original array and rearranges the original array. For example: ' Jsvar a = [1, 2, 3];a.reverse (). Join ("-"); = 3-2-1A//=>[3, 2, 1] "
| ' Array.join () ', stitching the elements in the array with the specified characters. For example: ' [1, 2, 3].join (-) ' results are ' n '; there is another way of invocation (based on array prototypes): ' ' JsArray.prototype.join.call ([3, 1, 4, 1, 5, 9, 2, 6], '-'); = "3-1-4-1-5-9-2-6"
| Pressing an element at the end of the array is the same as assigning a value to the array a[a.length]. "' Jsvar a = [];a.push (" one "); ["one"]a[a.length] = "one"; ["One", "both"] "
| A sparse array is not created when the value is omitted from the array's direct quantity. The omitted element is present in the array and its value is ' undefined '. --p147 "Jsvar a1 = [,,,]; The array is [Undefined, undefined, undefined]var a2 = new Array (3); The array has no elements at all 0 in a1//= True:a1 has an element at index 0--undefined.??? , in Chrome56.0, its value is false, and if a1=[undefined, undefined, undefined], the result is true0 in a2//= FALSE:A2 at index 0 no element "'
| The array can accommodate a maximum of ' 2^32-1=4 294 967 295 ' elements.
| Non-standard method: Two underline as prefix, two underline to do the suffix method. For example: ' __lookupgetter__ (), __lookupsetter__ () '. --p138
# Seventh Chapter
| Based on compatibility considerations, it is not recommended to use ' __proto__ ', ie and opera have not yet implemented it. --p139
| ' Object.defineproperty (Parameter 1: object, Parameter 2: property name to be created or modified, Parameter 3: Property descriptor Object) ' method can be used to set properties of attributes, some attribute of a new property. Property Descriptor: ' {value:1, writable:true, Enumerable:false, configurable:true} ', do not include all 4 attributes, for example: ' {value:2} '; for newly created properties, The default attribute value is ' false ' or ' undefined '. --p136

| Object Direct Volume: var a = {x:1, y:2} The direct amount of the object is an expression, each operation creates and initializes a new object, and if the object is used directly in the loop body in a repeating function, it creates many new objects;--p120http:// Www.cnblogs.com/jiuyi/p/4226903.html
| Strict mode ("Use strict" is an instruction introduced by ECMAScript 5) ' js//c = ' DD '; There is no expression "use strict"//as instruction d = "D1" before ' use strict '
"' JSC =" DD ";" Use strict "//is treated as a normal expression statement. d = "D1";
| The significance of strict mode: fixed the important flaw of language, and provided robust error-checking function and enhanced security mechanism. --p115

| With the usage of ' ' ' js//==> with test var o = {x:1};console.log (o); = = {X:1}with (o) x = 12;console.log (o); = = {X:12}: The WITH statement can be used to modify the value of a property in an object.
var o = {};with (o) x = 13;console.log (o); + = {}:with provides a shortcut to read the properties of O, but cannot create properties of O. Console.log (x); + 13: If O has no attribute x, then this code is equivalent to ' x=13 '
| It is forbidden to use the ' with ' statement in strict mode, and it is not recommended in strict mode, try to avoid using the ' with ' statement. (difficult to optimize, slow to run)--p113
| Get user input from the browser client by means of ' Prompt ("msg"). Pop up the message by means of ' alert (' msg ') '.
| If the function that throws the exception does not handle its ' try/catch/finally ' statement, the exception propagates up to the code that called the function. If no exception handler is found, JavaScript treats the exception as a program error. --p110
| The return statement can only appear in the function body, otherwise it will report a syntax error. --p109
| Functions, which can be defined in two ways:--p62, p57,p95

"' js//" method defines an expression: var square = function (x) {return x * x;} Way 2--Function declaration statement: Functions Square (x) {return x * x;} ```
The difference between the two is that-with Var, only the variable declaration is ahead of time-the initialization code of the variable is still in its original position. -The function name and function body are in advance using the function declaration statement.
As an example:
"'" js//==> function declaration in advance test;//Call Console.log before function initialization ("Call ============= before Code definition");//F1 (); =&GT;TYPEERROR:F1 is not a functionf2 (); = F2
function definition where var f1 = function () {Console.log ("F1")}function F2 () {console.log ("F2")}
Console.log ("Call ============= after Code definition"); F1 (); = F1f2 (); = "F2"
The whole is displayed "ahead" to the top of the script or function.
| Local variables in the function body are declared ahead of time, and the global variable with the same name is overwritten--p58> the variable declaration in the function "ahead" to the top of the function body, while the variable initialization remains in its original position.
| In JavaScript, If,else's matching rule is that else always matches the nearest if statement (preferably in curly braces for reading and comprehension). --p97
There is no block-level scope in JavaScript. --p93
Delete: Some built-in core and client properties cannot be deleted, and variables declared by the user through the Var statement cannot be deleted. --p89
Usage scenarios for ternary operators:--87 If there is a definition, use the defined, and use the default if there is no definition. "' Jsvar greeting =" Hello "+ (username? Username:" There ");
Why do you have the following usage? The execution of p.x depends on p, and if you do not use this "&&" way, then the type error exception is thrown. --p80 ' Jsvar p = null;p && p.x//short-circuit to determine whether the subsequent expression continues operation '
False values are ' false, null, undefined, 0,-0, Nan, and ' ', all other values including the object are true. --p79
All lowercase ASCII letters are "greater than" uppercase ASCII letters. --p77
The array is also the object ' jstypeof [] = = = = "Object"; =>true ""
The expression ' x!==x ' is established only when ' x ' equals ' NaN '. --p75
True is converted to 1 during the comparison. "JS1 = = true//= True2 = TRUE//= False"
Nan and any other values are not equal (including itself). --p75
The number of bits moved by the bitwise operation Range is: 0-31. Why? Because the bitwise operator requires that its operands be integers, these integers are represented as 32-bit integer instead of 64-bit floating-point;-p73
In JavaScript, all numbers are floating-point, and the result of the division operation is floating-point. --p70
If the operand is Nan, the result of the operation is also Nan. --p70
All operands that cannot be converted to numbers are converted to Nan when the arithmetic operation is performed. --p70
Binding: Unary operators, assignments, and ternary conditional operators all have a right-to-left binding. --p69
Note: Use square brackets when the property name is a value that is calculated by an operation instead of a fixed value. --p64
The point is simpler to use (compared to square brackets), but the property name you access must be a valid identifier, and you need to know the name of the property. --p63
For cases where a property name contains a space, it can be represented by ' [] ', for example: ' Jsvar p = {' Ni hao ': ' Hello '};p ["Ni Hao"]//= = "
The property name in the direct amount of the object can be a string rather than an identifier. --p62 ' Jsvar c = {"A B": 1, "D": 2}c["a B"]//+ = 1: This case is to be referenced by square brackets c["D"]//= = 2C.D//= 2 "
An array of direct amounts in the list between the comma elements can be omitted, and the omitted slots are populated with ' undefined '. Elements of the array's direct volume * * The end of the list * * can leave a single comma, this time does not create a new ' undefined ' object. --p62
Add a line to the beginning of the JS statement ' use strict; ' to enable strict mode;
Variable names with the same name, and local overrides are global. Notice the issue of the Declaration in advance.
Always use ' var ' to declare variables (do not hide Var). --p56
' New Boolean (false) ' is an object, not the original value. So the following code prints ' 1 ': ' Jsvar c = new Boolean (false), if (c) {//= = 1 Console.log (1);} else {console.log (2);}
if (c.tostring ()) {//= + 1: note: "false"! = False Console.log (1);} else {console.log (2);} ```
In terms of terminology, object values are references, and object comparisons are reference comparisons: they are equal when and only if they reference the same base object. --p48 ' Jsvar a = {a:1, B:2};var B = {a:1, b:2};a = = = b//= = False
b = A;a = = = b//= = True ""
Strings in JavaScript are equal to ' = = = ': When and only if their lengths are equal, and the characters of each index are equal. --p47
A JavaScript object is a composite value: It is a collection of properties or named values. --p46 when a property value is a function, it is called a method. The call is made in such a way as ' o.m () '.
Any JavaScript value can be converted to a Boolean value. All other values, including all objects (arrays), will be converted to true. --p43 "Jsundefinednull0-0nan" "//Empty string (Note: If there is a space in the middle of the words is not OH)"

The text between the two slashes forms a direct amount of a regular expression.
Direct volume (Regular direct volume, object direct volume, number, string ...) If you are not assigned to a variable, you can use it only once.
Solution for rounding Errors: use integer "Points" instead of fractional "tuples" for currency unit-based operations. --P38 (operation in more precise units)
Binary floating-point notation does not accurately represent simple numbers like 0.1. --p37
Except as a divisor, ' 0 ' and '-0 ' are identical. "' Jsvar zero = 0;var Negz = -0;zero = = = Negz; = = True1/zero = = = 1/negz; = = false: Positive infinity and negative infinity are different ""--p37

When and only if X is ' NaN ', the expression ' x! = X ' is ' true ';--p37

Infinite value after subtraction operation, the result is still infinite. "' jsinfinity/0 = infinity;infinity/-0 =-infinity;infinity/-1 =-infinity;"
Arithmetic operations in JavaScript do not error when overflow, underflow, and divide by zero:--p36 "js3/0 = infinity;-3/0 =-infinity;"

Octal (octal is not recommended, in strict mode of ECMAScript 6, 8 is forbidden): 0377 is octal; 0378 is decimal; (Can be verified via console)--p35
Floating-point range (with IEEE 754 standard): Maximum (Infinity away from 0): +-1.7976931348623157 x 10^308 min (infinity close to 0): +-5.0 x 10^-324 (Note: The minimum value here is relative to 0.) )--p34
Digital Direct Volume: A number appears directly in the JavaScript program. By adding '-' symbols before any number direct, you can get their negative values. But the minus sign is a unary negation operator and is not part of the digital direct volume syntax. P34
All numbers in JavaScript are represented by floating-point numbers.

A variable that is not declared inside any function is called a global variable, and it is visible anywhere in the JavaScript program. A variable declared within a function has a function scope and is visible only within the function. --p34

# # # Optional semicolon in JavaScript, the semicolon of the split statement is optional. JavaScript does not fill a semicolon at all line breaks: JavaScript fills semicolons only if the code is not parsed correctly without a semicolon; Exception 1: note: ' Return ', ' break ', ' Continue ' There is no line break between the and subsequent expressions (the semicolon is added automatically). Exception 2: When the ' + + ', '--' is involved, it can be either a prefix or a suffix. If it is a suffix expression, it should be placed on the same line.

# # # Data types in programming languages, the types of values that can be represented and manipulated are called data types.
Technically, only JavaScript objects can have methods. However, numbers, strings, and Boolean values can also have their own methods. Only ' null ' and ' undefined ' in JavaScript cannot have a method;


--------------<start>------


Errors in # # # Books | The p75 result should be equal, and this and the fourth description of Nan are contradictory. > If two values are null or both are undefined, they are not equal. = = They are equal
| P77> need to first convert all the strings to lowercase letters = = ALL the strings must first be converted to lowercase letters
| P113> width, debugger, and use strict = = with, debugger, and use strict
| P159> for the sake of simplicity, to the present position = so far
| p168> try/cache/finally = try/catch/finally
| P177> elements in array A that must be numeric, NULL, and undefined are ignored. = ', ' modified to ', '
| P203> Prototye Properties = = Prototype Property
| p204> var r = Range (1, 3); = = var r = new Range (1, 3);
| p205> keyword Mew + = keyword New

| P213> but we often feel the constructor attribute on the prototype. = = But we often ignore the constructor attribute on the prototype.
| p260>/\s\javas/=/\sjava\s/
| P260> with "(?!!") Assertion is a negative lookahead assertion that specifies that the next character does not have to match. = = with "(?!" Assertion is a negative lookahead assertion that specifies that the next character does not match.

| P263> the next discussion of the Exec () method will refer to:=> 's next discussion of the exec () method. (The last punctuation mark should be a period)


Null

JavaScript authoritative Guide notes-part 1th

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.