javascript - What is an ECMAScript "native object"? - Stack Overflow

According to the ECMA-262 a native object object in an ECMAScript implementation whose semantics are fu

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?

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?

Share Improve this question asked Nov 8, 2011 at 15:09 P.Brian.MackeyP.Brian.Mackey 44.3k71 gold badges248 silver badges358 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

They're "native" because they e 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

  • Mozilla's numerous JavaScript extensions — such as WeakMap() or __proto__
  • JScript's ActiveXObject() constructor and (undocumented) CollectGarbage() function

Examples of host objects

  • DOM objects, document and window
  • console

The semantics of a native object are fully defined by ECMA-262. The object itself may not be.

So we have three levels of objects:

  1. Standard built-in objects: defined ECMA-262, and follow ECMA-262 semantics. Example: Object.
  2. Other built-in objects: not defined in ECMA-262, but follow ECMA-262 semantics. Example: setTimeout.
  3. Host objects: don't follow ECMA-262 semantics; they can have weird behavior of any sort, and interact with EMCA-262 built-in objects in weird and unexpected ways (for example lying about various internal properties). Example: NodeList.

The definition of native object is the relative term of host object
Like window.console object is a host object which Ecma262 haven't been documented to tell the browser how to implement it.
And Ecma262 is just a project to specify the language the feature. ECMAScript implementation actually is browser's business. That means the implementation pliant to the specification on the object type, we can say it built-in object though they does not work exactly the same.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745210072a4616784.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信