JS Object Type
JS, the object can be divided into "internal object", "host Object" and "custom object" three kinds.
1. Local objects
ECMA-262 is defined as "the object provided by the JS implementation of the hosting environment." In simple terms, a local object is a class (reference type) defined by JS. They include:
object/function/array/string/boolean/number/date/regexp/error/evalerror/rangeerror/referenceerror/syntaxerror/ Typeerror/urierror
2. Built-in objects
ECMA-262 defines the built-in object as "all objects that are provided by the JS implementation, independent of the hosting environment, and appear when the JS program starts executing". This means that the developer does not have to instantiate the built-in object explicitly, it has been instantiated. JS only defines two built-in objects, Globa and math (they are also local objects, by definition, each built-in object is a local object)
all properties of the global object
Property |
Description |
Property |
Description |
Undefined |
Special value undefined |
Date |
Constructor date |
NaN |
Special Value Nan |
Regexp |
Constructor RegExp |
Infinity |
Special Value Infinity |
Error |
Constructor error |
Object |
Constructor Object |
Evalerror |
Constructor Evalerror |
Array |
Constructor array |
Rangeerror |
Constructor Rangeerror |
Function |
constructor function |
Referenceerror |
Constructor Referenceerror |
Boolean |
Constructor Boolean |
SyntaxError |
Constructor SyntaxError |
String |
Constructor string |
TypeError |
Constructor TypeError |
Number |
Constructor number |
Urierroe |
Constructor Urierror |
Attention:
- Distinguish between object definitions and global constructors
- Built-in objects are one of the local objects
3. Host Object
The host object is the object provided by the environment that executes the JS script. For JS embedded in the Web page, its appeal object is the object provided by the browser, so it is also called the browser object, such as Chrome/ie/firefox, such as browser-provided objects. Different browsers provide host objects that may be different, provide the same objects in a timely manner, and do so differently! This can lead to browser compatibility issues and increase the difficulty of development. All BOM and Dom objects are host objects.
- BOM objects include: Window object, Location object, navigator object, Screen object, History object
- The DOM object is a node object, including the type: node/document/element/text/comment/cdatsection/documenttype/attr
4. Custom Objects
A custom object is a developer's own defined object. JS allows the use of custom objects, so that JS applications and functions are extended.
The relationship between JS objects
1. instanceof operator
Instanceof operator judgment mechanism, such as: Subclass instanceof Superclass;
If the object subclass is found in the prototype chain of the object superclass, then the instanceof operator returns True, no in return false
In other words, the object is constantly backtracking through the __proto__ property, and if __proto__ passes through the prototype property of an object, the instanceof operator returns true, otherwise false.
2, the relationship between JS objects
Diagram to illustrate the relationship between JS objects:
So from the diagram we can draw:
Object instanceof Function//trueFunction instanceof Object//true(Array/boolean/string/number/date/regexp/error) instanceof Object/function//true(Array/boolean/string/number/date/regexp/error.prototype) instanceof Object//true(Array/boolean/string/number/date/regexp/error.prototype) instanceof Function//false(NewArray/boolean/string/number/date/regexp/error) instanceof Object//true(NewArray/boolean/string/number/date/regexp/error) instanceof Function//falseFoo instanceof (Function/object)//truefoo.prototype instanceof Object//truefoo.prototype instanceof Function//false(NewFoo) instanceof Foo/object//true(NewFoo) instanceof Function//false
The relationship between JS objects