Local objects in JS, built-in objects and host objects

Source: Internet
Author: User
Tags hosting

First, the host environment is explained: The general hosting environment is created and maintained by the shell, as long as the environment can provide the JS engine execution can be called the shell program. such as: Web browser, some desktop application system, etc. That is, the Web browser or these desktop application systems have long been the environment, the hosting environment.

Local objects

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

Take a look at what "local objects" contains:

Object, Function, Array, String, Boolean, number, Date, REGEXP, Error, Evalerror, Rangeerror, Referenceerror, SyntaxError, TypeError, Urierror

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

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 "local objects". ECMA-262 only defines two built-in objects, Global and Math (they are also local objects, by definition, each built-in object is a local object).

So it's understandable. Built-in objects are one of the local 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 actually exist at all, but it is clear that 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. For the specific methods and properties of the global object, interested students can look at this: JavaScript Global object reference manual

Host Object

The object provided by the hosting environment, implemented by ECMAScript, can be understood as: the object provided by the browser. All of the BOM and Dom are host objects.

Summarize:

JS, the object can be divided into "internal object", "host Object" and "custom object" three kinds.

1, Internal object

The internal objects in JS include array, Boolean, Date, Function, Global, Math, Number, object, REGEXP, string, and various error class objects, including errors, Evalerror, Rangeerror, Referenceerror, SyntaxError and TypeError.

The two objects, global and math, are also known as "built-in objects," which are created when the script is initialized and do not have to instantiate both objects.

2. Host objects

The host object is the object provided by the environment that executes the JS script. For JS embedded in the Web page, the host object is the object provided by the browser, so it is also called the browser object, such as IE, Firefox and other browser-provided objects. Different browsers provide host objects that may be different, even if they are provided with the same object, and they are implemented in a variety of ways! This can lead to browser compatibility issues and increase the difficulty of development.

There are many browser objects, such as window, document, and so on.

3. Custom Objects

As the name implies, it is the developer's own defined object. JS allows the use of custom objects, so that JS applications and functions are expanded

Local objects in JS, 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.