Home  >  Article  >  Web Front-end  >  Various object relationships in JS

Various object relationships in JS

不言
不言Original
2018-04-10 14:20:441328browse


A picture allows you to understand the relationship between various types of JavaScript

This picture comes from page P184 of Chapter 3 of "The Essence of JavaScript Language and Programming Practice". Recently I am revising the second edition, and this picture has been redone. You can refer to it if necessary.

In addition, I would like to add the concepts used in the picture:

1. Built-in The difference between (Build-in) objects and native (Naitve) objects is that the former is always created during the engine initialization phase and is a subset of the latter; while the latter includes some objects that are dynamically created during running object.

2. Engine extension objects are a collection that is not too large. Generally speaking, it is relatively certain that they are also native to the engine. Object (but not a native object of the ECMA specification).

3. The host object is not a native object of the engine, but an object registered by the host framework into the JavaScript engine through some mechanism. .

4. Some hosts will also call the objects/constructors they provide as "native objects", such as Internet Explorer 7 calls the XMLHttpRequest() it provides native - as opposed to the objects created through methods such as "new ActiveXObject('Microsoft.XMLHTTP')" in earlier versions of it. In this case, readers should note the difference between "host's native objects" and "engine's native objects".

Reprinted from: http://www.w3cfuns.com/thread-5594427-1-1.html

##JavaScript local objects, built-in objects, host objects


Native object (requires NEW)

ECMA-262 defines native object as "ECMAScript independent of the host environment" Implement the provided object".

Object, Function, Array, String, Boolean, Number, Date, RegExp, Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, ActiveXObject (server), Enumerator (collection traversal class), RegExp (Regular expression)

It can be seen that, simply put, local objects are classes (reference types) defined by ECMA-262.


Built-in objects (no NEW direct reference - only MATH GLOBAL)

ECMA-262 Built-in object) is defined as "all objects provided by an ECMAScript implementation, independent of the host environment, that appear when an ECMAScript program begins execution." This means that the developer does not have to explicitly instantiate the built-in object, it is already instantiated.

It is also "independent of the host environment". According to the definition, it seems difficult to distinguish the difference between "built-in objects" and "local objects". ECMA-262 only defines two built-in objects, namely Global and Math (they are also local objects, and by definition, every built-in object is a local object).

So you can understand it. Built-in objects are a type of local objects. Among the two objects it contains, we often use the Math object, but what is this Global object?

The Global object is the most special object in ECMAScript, because in fact it does not exist at all! In ECMAScript, there are no independent functions, all functions must be methods of an object.

Similar to the isNaN(), parseInt() and parseFloat() methods, they all appear to be functions, but in fact, they are all methods of the Global object. And the Global object's methods don't stop there. For the specific methods and properties of the Global object, interested students can take a look here: JavaScript Global Object Reference Manual

Host Object (BOM DOM & Custom Object)

What is a "host object"? The "host" in ECMAScript is of course the running environment of our web page, that is, the "operating system" and "browser". All non-native objects are host objects, that is, objects provided by the host environment of the ECMAScript implementation.

All BOM and DOM objects are host objects. Because it displays different contents for different "host" environments. In fact, to put it bluntly, the objects that are not officially defined by ECMAScript belong to the host object, because most of the undefined objects are objects created by the ECMAScript program. TML DOM is a W3C standard (the abbreviation of HTML Document Object Model, Document Object Model for HTML).

HTML DOM defines a standard set of objects for HTML, as well as standard methods for accessing and processing HTML documents.

Through the DOM, you can access all HTML elements, along with the text and attributes they contain. The content can be modified and deleted, and new elements can also be created.

DHTML DOM is platform and programming language independent. It can be used by any programming language such as Java, JavaScript and VBScript.

Click the link below to get more knowledge about how to use JavaScript to access and manipulate DOM objects:

DOM Object:

Document represents the entire HTML document and is used to access all elements in the page. Anchor Representative element. Area represents the element in the image map. Base represents element. Body represents the element in the image map. Button represents