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();
)?
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.
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.
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.
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
, ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With