Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between native objects and host objects?

I don't understand the difference between native objects and host objects in JavaScript. Does the latter simply refer to non-primitive function objects that were created by a custom constructor (e.g., var bird1 = new Bird();)?

like image 277
ppecher Avatar asked Sep 30 '11 18:09

ppecher


People also ask

Is integer a native object in JavaScript?

JavaScript has several built-in or native objects. These objects are accessible anywhere in your program and will work the same way in any browser running in any operating system. JavaScript Number Object − The Number object represents numerical date, either integers or floating-point numbers.

What are object properties?

Object properties differentiate objects from other objects. The basic properties of an object are those items identified by its four-part name (name, type, instance, and version) and also include owner, status, platform, and release.

What is the new operator in JavaScript?

The new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.


1 Answers

Both terms are defined in the ECMAScript specification:

native object

object in an ECMAScript implementation whose semantics are fully defined by this specification rather than by the host environment.

NOTE Standard native objects are defined in this specification. Some native objects are built-in; others may be constructed during the course of execution of an ECMAScript program.

Source: http://es5.github.com/#x4.3.6

host object

object supplied by the host environment to complete the execution environment of ECMAScript.

NOTE Any object that is not native is a host object.

Source: http://es5.github.com/#x4.3.8


A few examples:

Native objects: Object (constructor), Date, Math, parseInt, eval, string methods like indexOf and replace, array methods, ...

Host objects (assuming browser environment): window, document, location, history, XMLHttpRequest, setTimeout, getElementsByTagName, querySelectorAll, ...

like image 111
Šime Vidas Avatar answered Sep 19 '22 21:09

Šime Vidas