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

后端 未结 2 1322
小鲜肉
小鲜肉 2021-01-21 10:23

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

相关标签:
2条回答
  • 2021-01-21 11:16

    Native object - means implemented not in ECMAScript itself. Buiilt-in object - the one that's provided by the engine. Think Math, String and such.

    0 讨论(0)
  • 2021-01-21 11:24

    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.

    0 讨论(0)
提交回复
热议问题