Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

javascript - What is an ECMAScript "native object"?

According to the ECMA-262 a native object

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

A built-in object is defined as

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

with a 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.

If a native object is fully defined by the ECMA-262 specification rather than the host environment and an ECMAScript implementation may specify and define new built-in objects, how is it that these new built-in object's can be native objects when they are not fully defined by the ECMA-262 specification?

What am I missing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

They're "native" because they come with the ECMAScript implementation. A host environment in generally an application consisting of an ECMAScript implementation and several other interfaces that work together. For instance,

  • Web Browser — a host environment consisting of ECMAScript implementation, DOM interface, Rendering engine, UI, etc.
  • Windows Script Host — a host environment consisting of ECMAScript implementation, VBScript implementation, etc.
  • Node.js — a host environment consisting of ECMAScript implementation (V8), HTTP interfaces, etc.

"Built-in" objects are required to inherit from Object or Function, whereas host objects — objects provided by the host environment, but not necessarily present at the start of execution — are not required to but may (and sometimes do).

Examples of native objects defined by ECMA-262

  • Object(), Array(), Date()
  • Math, JSON, the Global object.

Examples of native, built-in objects not defined by ECMA-262

Examples of host objects

  • DOM objects, document and window
  • console

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...