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
851 views
in Technique[技术] by (71.8m points)

javascript - In ECMAScript, how are some of native objects also built-in?

I suppose a definition of native and built-in objects is required to answer this question. Here's what the ECMAScript spec defines these as:

4.3.6 native object

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

NOTE Standard native built-in 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.

I'm looking forward to an explanation of this one.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Here is what ES5 shows:

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.

As you can see, it's different that what you've shown.

Built-in objects are native objects made available by the ECMAScript-compliant engine. For example:

  • String
  • Object
  • Array
  • Undefined
  • Boolean
  • etc.

A native object is, for example:

var obj = {};

Or the list shown before. Built-in objects are native.

Also, you didn't show it, but a host object is an object dependant on the environment. For example, in browsers, the host object is window. There are other host objects such as document or XMLHttpRequest though.


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

...