Current location - Quotes Website - Personality signature - Advanced TS Advanced Type, Universal
Advanced TS Advanced Type, Universal
Intersection type is a combination of multiple types into one type.

Joint type means that a value can be one of several types.

Using type assertions requires multiple judgments, which is very troublesome. So use type protection.

Typeof can only be used for numbers, strings, booleans and symbols (only these types are considered as type protection).

For any type of t, the result of keyof T is the union of known public property names on t.

1) First, use the keyof keyword, which is an index type query operator, and it can get the union of the known public * * * attribute names on any type T. As shown in the example, keyof T is equivalent to "name' | 'age".

2) Then, k extends the keyof T, indicating that the value of k is limited to' name' | 'age'.

3 ), T[K] indicates the type of the corresponding key element in the object.

Keyof and T[K] interact with string index signatures. If you have a string index signature type, then the key of T is a string. T[string] is the type of index signature:

Its syntax and syntax type of index signature are used internally for .. inches. It has three parts:

We can also write more general mapping types, such as:

/Archives /266/

Conclusion:

(1) This is always equal to currentTarget, which is a node object bound by the listener function of the event.

(2) target refers to the node object of the listener function that initially triggered the event.

Example:

The idea of js inheritance mechanism: all the attributes and methods of prototype objects can be enjoyed by instance objects.

By default, the prototype object has a constructor property that points to the constructor where the prototype object is located by default.

Instanceof returns a Boolean value indicating whether the object is a constructor instance.

Object.getPrototypeof () returns the prototype of the parameter object, which is the standard method to obtain the prototype object.

Object.setPrototypeof(a, b) sets the prototype of the parameter object and returns the parameter object.

Object.create () takes the parameter object as the prototype and returns the instance object.

The isPrototypeof method of an instance object is used to determine whether the object is a prototype of a parameter object.