This article follows the reference type (top) of JavaScript advanced programming, and continues below:
Date type
Date is a date class that can be used to get the date and time and the number of milliseconds for the specified date. The date class provides a rich API that can be understood through the documentation on the MDN: Click here to jump to MDN, which is not explained in detail here.
RegExp type
Regular expression is absolutely a tool in programming language, no disadvantage, in daily coding will often use regular to match something. JS in the regular, can be created in two ways: the literal form and the instantiation of the constructor mode. It is important to note that the literal creation of the regular, will share an instance, the way of instantiation, each instantiation will create a new instance. Because the regular learning curve is relatively high, not an article can be explained clearly, so here is not to explain, specifically about the JS regular expression content can click here
function type
The function in JS is also an object, and each function is an instance of functions. There are three ways to declare functions, the first: functionsum () {statement .... }. Sum is the name of a function, which is a pointer or reference to a function. The second type:const SUM = function () {statement ...}. This is called a function expression, and it has no difference from the first way. The declared constant sum stored is still a reference to the function. The last is the way to instantiate the constructor, for example:const SUM = new Function ("Parameters:", "Parameters ...", "statement ...."). Its last argument is always the statement that the function will execute. The third way of declaring it is not recommended because it resolves two times, parses the regular code for the first time, and parses the string passed into the constructor for the second time, thus affecting performance.
No overloads: overloading is an attribute in an object-oriented programming language that performs different implementations when called, depending on the parameters passed in. Java. NET has this feature, but our JS does not have this feature. JS declares two functions of the same name, equivalent to assigning two values to the function name, which overrides the first assignment for the last time. Although the function is not overloaded, we can use the arguments parameter list of the function to simulate overloading.
1 functionABC (x, y)2 {3 if(Arguments.length = = 3)4 {5 returnX+y+arguments[2];6 }7 Else8 {9 returnX +y; Ten } One}
Simulate overloading
This example, because of the number of parameters passed in, the implementation of different implementations, so as to achieve the same effect as overloading.
function declarations and function expressions: The two methods are different in the order in which they are executed, and the parser prioritizes the function declaration, guaranteeing that the function can be called normally wherever it is called. This parsing method is called a function declaration in advance. The function expression is not parsed, and the parser waits for the line of code it is in to begin parsing, that is, the function expression cannot be called before it is defined.
functions as values : Because functions can be assigned to variables, functions can also be passed into functions as arguments, or returned as return values. In everyday programming, these two methods are often used.
built-in properties for functions : Within a function, there are two properties, one is arguments and the other is this. Arguments is a class array object that stores all the parameters of a function. It has the length property, as well as the array, and it can access the stored values in the same way as arrays. In addition to this, arguments has two properties, callee and caller. Callee stores a reference to the current function. Caller refers to a function that invokes the current function. Currently, the two properties are forbidden in strict mode, so use these two attributes sparingly in programming. The This object points to the object of the current execution environment, which in the default function points to the Global Object window, the this in the constructor, to its own execution environment object.
properties and methods of functions : Functions act as objects, owning their own properties and behaviors. The attributes have length and prototype. Length refers to the number of function parameters, prototype is a prototype attribute, after the article will be described in detail, here is not much to say. Methods are call, apply, and bind. Call and apply have the same function, are called functions, change the function of the execution Environment object (that is, this point), the difference is its incoming parameters. The second parameter of the aplly receives an array, and call passes a variable number of arguments separated by commas. The function of BIND is to bind this to the function and return the function, and also receive two parameters, the first is the this object to bind, and the second is a variable number of arguments.
Basic Package Type
The basic wrapper type is to wrap the base type into objects so that they can use properties and methods. The basic wrapper type in JS is number, Boolean, String. Basic wrapper types, which are the simplest value types if you don't use properties and methods, but when you use properties and methods, they become objects. The basic wrapper type has a short life cycle, just like the front, which becomes an object only when used, and is destroyed immediately after use. So when you add a custom attribute to them, the browser will give you an error. However, if we need to, we can use number (), String (), Boolean () to display the creation.
Boolean type
Boolean is a reference type representation of a Boolean type. Using the constructor Boolean (), passing in true and false, creates the corresponding reference type. Creates a reference type, with typeof detection, a normal Boolean type, returns "Boolean", but a reference-type Boolean, which returns "object".
Number Type
Number is a reference representation of the base numeric type. It provides several methods for formatting numeric values. The ToFixed () method returns a string representation of the decimal number of the specified decimal place. The parameter is a number that indicates that several decimals are retained and can support 0-20-bit maximum. If the value is longer than the number of decimal digits reserved, the method rounds the numeric value. The Toexponential () method returns the string form of the numeric value represented by the scientific notation. Receives a parameter that also specifies the number of decimal digits. The Toprecision () method returns the most appropriate representation of a value, receiving a parameter that represents the number of digits of all digits of the numeric value.
String type
The
String type is the object wrapper type of a string, and it has a length property that indicates how many characters are contained in the string. It provides the following methods: character method : CharAt () returns the character at the specified position as a single-character, with a parameter that specifies where to return the character. charCodeAt () returns the character encoding of the specified position character, which receives a parameter that specifies where to return the character. string manipulation method: concat () is used to stitch together one or more strings and return the resulting new string. Slice (), substr (), substring () intercept the string and return the new truncated string. It all receives two parameters, a starting position, and an end position. The end position is optional and, if not passed, the default is truncated from the starting position to the tail of the string. The parameters of these three methods can be negative, and if negative values are passed, slice will add the passed arguments to the string length. SUBSTR will add the first argument to the length of the string and convert the second argument to zero for a negative value. SUBSTRING will convert all negative arguments to zero. string Position method : IndexOf and LastIndexOf, two methods will find the specified character in the string, and if found, returns the position of the character in the string. If not, returns-1. The difference between the two methods is to find one from scratch and the other to start at the end. Two methods also receive the second parameter, which specifies where to start the lookup. The Trim method is used to clear spaces on both sides of a string. string Casing Conversion method : Uppercase conversion method: toUpperCase, toLocaleUpperCase. Lowercase conversion methods: toLowerCase, Tolocallowercase. pattern Matching Method : the so-called pattern matching is the way that you can do certain things with regular strings. The match method receives a regular or regular expression that takes a string that conforms to the regular rule, generates an array, and returns. Seach receives a regular parameter, returns the index of the string that matches to the first item, or 1 if there is no match. The Replace method receives two parameters, one is a string or regular expression that needs to be replaced, and the second parameter is the specific value or function to be replaced. The split method separates the string as specified and returns an array. Receives two parameters, one parameter specifies the delimiter, and the other argument is optional, specifying the size of the returned array.
monomer built-in objects
Global Object
The global object is a relatively virtual object. The reason for this is that it is not visible in a running environment, but it does exist. Many properties and methods that do not belong to any object belong to the properties and methods of the global object, including the defined global variables and global functions. such as isNaN (), Isfinite (), parseint (), parsefloat (). They are used in a way that is indeed a global function, but they are, in fact, methods of global objects. In addition, there are other methods: encodeURI, encodeURIComponent methods for encoding URIs, and decodeURI and Decodeuricomponnent, which decode URIs.
Window object
Although JS does not indicate the path to the global object, the global object is displayed as part of the Window object in the browser environment. Therefore, the properties and methods of the global object become the properties and methods of the Window object.
Math Object
The Math object provides a series of methods for mathematical calculations, such as absolute values, rounding, sine, cosine, and so on. Please Click here for details.
Reference types of JavaScript advanced programming (bottom)