2

A native object is an object or class of objects defined by the ECMAScript specification. Arrays, functions, dates, and regular expressions (for example) are native objects.

A host object is an object defined by the host environment (such as a web browser) within which the JavaScript interpreter is embedded. [...] Host objects may also be native objects, as when the host environment defines methods that are normal JavaScript Function objects.

[JavaScript: The Definitive Guide, by David Flanagan (O’Reilly). Copyright 2011 David Flanagan, 978-0-596-80552-4.]

How can a host object (which is defined by the host environment) be a native object (for which it needs to be defined by the specification)? Can you give an example for the mentioned methods?

Community
  • 1
  • 1
  • According to the ES5 spec, "Any object that is not native is a host object." More information here: http://stackoverflow.com/questions/7614317/what-is-the-difference-between-native-objects-and-host-objects – Jordan Running Dec 07 '15 at 21:22
  • @Jordan I think the OP is asking about host objects that are also native objects. – Dave Newton Dec 07 '15 at 21:25

1 Answers1

2

ES5 has the following definitions:

4.3.6 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.

4.3.7 built-in object : object supplied by an ECMAScript implementation, independent of the host environment, that is present at the start of the execution of an ECMAScript program.

NOTE Standard built-in objects are defined in this specification, and an ECMAScript implementation may specify and define others. Every built-in object is a native object. A built-in constructor is a built-in object that is also a constructor.

4.3.8 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.

This final comment appears ambiguous, but I read the intent to be that native objects are not host objects (I could be wrong).

The nomenclature changes in ES2015. The term "native object" is not used there. The word "native" only occurs in the context of NativeError. The terms "built-in object" and "host environment of objects and facilities" are used however.

Ben Aston
  • 53,718
  • 65
  • 205
  • 331