Differences between native objects, built-in objects, and host objects

Source: Internet
Author: User

1. The difference between the built-in (build-in) object and the native (Naitve) object is that the former object is always created at the engine initialization stage and is a subset of the latter, while the latter includes some objects that are created dynamically during the run.

2, the engine extension object is a not too large collection, generally more determined, they also belong to the engine's native object (but not the ECMA specification of the native object).

3. The host object is not the original object of the engine, but is registered by the host framework with some mechanism in the JavaScript engine.

4, some hosts will provide themselves with the object/constructor also known as the "native object", for example, Internet Explorer 7 to the XMLHttpRequest it provides () is known as the original-in contrast to its earlier version of the "new ActiveXObject (' Microsoft.XMLHTTP ') the object created by this method. In this case, the reader should note the difference between the "native object of the host" and the "native object of the engine".

First, the native object

ECMA-262 defines native objects (native object) as "objects provided by ECMAScript implementations that are independent of the hosting environment."

Object, Function, Array, String, Boolean, number, Date, REGEXP, Error, Evalerror, Rangeerror, Referenceerror, SyntaxError, TypeError, Urierror, ActiveXObject (server side), Enumerator (Collection traversal Class), REGEXP (regular expression)

As you can see, the primitive object is simply a class defined by ECMA-262 (reference type).

Second, built-in objects

ECMA-262 defines the built-in object (built-in object) as "all objects that are provided by the ECMAScript implementation, independent of the hosting environment, and appear when the ECMAScript program starts executing." This means that the developer does not have to instantiate the built-in object explicitly, it has been instantiated.

It is also "independent of the hosting environment". By definition, it seems difficult to distinguish between "built-in objects" and "native objects". ECMA-262 only defines two built-in objects, Global and Math (they are also native objects, by definition, each built-in object is a native object).

So it's understandable. Built-in objects are one of the native objects. The Math object we use often in the two objects that it contains, but what is the global object?

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

Similar to the isNaN (), parseint (), and parsefloat () methods, and so on, all appear to be functions, and in fact, they are all methods of the global object. And the global object's approach is more than that.

Third, the host object

What is a "host object"? The "host" in ECMAScript is, of course, the operating environment of our web page, which is "OS" and "browser". All non-native objects are host objects (host object), which is the object provided by the hosting environment implemented by ECMAScript.

All BOM and DOM objects are host objects. Because it's different for different "hosting" environments. The truth is, ECMAScript, the official undefined object belongs to the host object, because most of its undefined objects are objects that are created by themselves through the ECMAScript program. The TML DOM is the standard (abbreviation for HTML Document object models, Document Object model for HTML).

The HTML DOM defines a series of standard objects for HTML, as well as a standard way to access and manipulate HTML documents.

Through the DOM, you can access all the HTML elements, along with the text and attributes they contain. You can modify and delete the content, and you can also create new elements.

Differences between native objects, built-in objects, and host objects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.