variables, scopes, and memory issues
- There are two types of execution environment-Global and local
- The scope chain is longer, there are two cases: the catch block of the Try-catch statement, the WITH statement.
- JavaScript does not have block-level scopes, which are variables in the if,for loop, and are not destroyed after the block has ended.
- It is a good idea to manually disconnect the native JavaScript object from the DOM element.
Object type
- There are two ways to create an object instance: The new operator is followed by the object constructor, new object (), and the object literal notation is denoted by {}.
- You can use the square bracket notation to access the properties of an object, and the property to be accessed is placed in square brackets in the form of a string.
- Square brackets access the properties of an object, which can be accessed by a variable
var propertyname = "Name"; Alert (Person[propertyname]);
The property name contains characters that cause syntax errors, or you can use square brackets
Array type
- There are two ways to create an instance of an object: The new operator is followed by the array constructor, the new object (), and the object literal representation is represented by [].
- The constructor of an array is not called when the array is created in the same way as the object, when it is called literal
- Detection array: Value instanceof array
- Array.isarray (value) supports ie9+ ...
- The ToString () method of the array returns a comma-delimited string of strings for each value string in the array; call valueof () returns or arrays
- Use push () and pop () to simulate the stack method, using push () and shift () to simulate the queue method
- The Concat () method creates a copy, adds the received parameter to the end of the copy, and does not change the original array
- Slice () receives a parameter that returns all items from the specified position to the end, and if two parameters, returns the item from the specified start position to the end position, excluding the end position. Also, the slice () method does not affect the original array.
- Splice () method
Delete |
2 parameters |
To delete the first item position, to delete the number of items, example splice (0,2) |
Insert |
One parameter |
Starting position, 0 (number of items to delete), the item to be inserted, example splice (2,0, "Red", "yellow") |
Replace |
One parameter |
Starting position, to delete the item number, the item to be inserted, example splice (2,1, "Red", "yellow") |
- Iterative methods
Every () |
Runs the given function for each item of an array, and returns TRUE if each item returns true |
Filter () |
Each item of an array runs the given function, and returns the list of items that the function returns True |
ForEach () |
Runs the given function for each item of an array, and the function does not return a value |
Map () |
Runs the given function for each item of the array, returning each time the result of the call is returned |
Some () |
Runs the given function for each item of an array, and returns True if the function returns true for either item |
Support for iterative methods requires ie9+
- Narrowing method Values.reduce (function (Prev,cur,index,array) {}), also requires IE + +
Date type
- UTC creation time: var allfives = new Date (DATE.UTC (2005,4,5,17,55,55,55)), originally according to the book, should be May 5, 2005 5:55 P.M. 55 seconds, But I run the time is May 6, 2005 1:55 55 seconds, because my time zone is East 8, plus 8 o'clock
- var allfives = new Date (2005,4,5,17,55,55,55), the time of creation can be the corresponding result.
- Date.now () supported browsers for ie9+
- In browsers that do not support the now () method, you can use the following methods to count the time between two pieces of code
var start = +new Date (); dosomething ... var end = +new Date (); Console.log (End-start);
- Method of date formatting
toDateString () |
Display weekday, month, day, and year in a realistic-specific time format |
toTimeString () |
Display hours, minutes, seconds, time zones in a realistic-specific time format |
toLocaleDateString () |
Display days, months, days, and years in a locale-specific time format |
toLocaleTimeString () |
Display hours, minutes, seconds in a realistic-specific time format |
toUTCString () |
Full UTC date in a realistic-specific format |
Regular expressions
- Regular expression: var expression =/pattern/flags;
- There are three flags: G is global, I table is case insensitive, M is multi-line matching
- RegExp Instance Properties
Global |
Boolean value, whether the G flag is set |
IgnoreCase |
Boolean, whether the I flag is set |
LastIndex |
An integer that represents the character position at which to start searching for the next occurrence, starting from 0 |
Multiline |
Boolean value, whether the M flag is set |
Source |
A string representation of a regular expression that is returned in literal form rather than in the character pattern in the passed-in constructor |
- Regular Expression Constructor properties
Long attribute name |
Short attribute name |
Description |
Input |
$_ |
The last string to match, opera is not implemented |
Lastmatch |
$& |
Last match, opera not implemented |
Lastparen |
$+ |
Last matched capture group, opera not implemented |
Leftcontext |
$` |
Text before lastmatch in the input string |
Multiline |
$* |
Boolean value indicating whether to use multiline mode, IE and opera are not implemented |
Rightcontext |
$ |
Text after lastmatch in the input string |
- The method of the regular expression var matches = Pattern.exec (text) "Returns the result set" and pattern.test (text) "Returns True, false".
- The Text.match (pattern) method of string type is the same as pattern.exec (text)
function type
- Arguments.callee () calls the current function, which is not supported by strict mode
- This refers to the function object on which the function is executed
- Caller This function holds a reference to a call to the current function and returns null if the current function is called in a global variable
- Each function contains two properties: Length and prototype, where length indicates the number of named arguments that you want to receive
String type
- The second parameter of the replace () method can be a function that passes three parameters in the case of only one match: pattern match, pattern match position in string, and original string
function Htmlescape (text) { return Text.replace (/[<> "&]/g,function (match,pos,originaltext) { Switch (match) {case "<": return "<"; Case ">": return ">"; Case "&": return "&"; Case "\" ": Return" "";}} );
- There are several methods related to the matching pattern: match (), search (), replace (), and split () can pass in the regular expression.
Math Object
- Approximate values are calculated as follows: Ceil (), round (), Floor ()
- A method of randomly selecting a value from an integer range: value = Math.floor (Math.random () * Total number of possible values + first possible value)
Reading "JavaScript advanced Programming" Note Two-variables, scopes, memory, and reference types