Home  >  Article  >  Web Front-end  >  What are the built-in objects in ecmascript?

What are the built-in objects in ecmascript?

青灯夜游
青灯夜游Original
2021-12-06 15:23:391589browse

The built-in objects in ecmascript include: global object, Object object, Function object, Array object, String object, Boolean object, Number object, Math object, Date object, RegExp object, JSON object, and Error object.

What are the built-in objects in ecmascript?

The operating environment of this tutorial: Windows 7 system, ECMAScript version 6, Dell G3 computer.

ECMAScript defines a set of built-in objects that outline the definition of ECMAScript entities.

These built-in objects include:

Global object, Object object, Function object, Array object, String object, Boolean object, Number object, Math object, Date object, RegExp object , JSON object, and Error object: Error , EvalError , RangeError , ReferenceError , SyntaxError , TypeError , URIError .

Global Object

The only global object is created before control enters any execution environment.

Unless otherwise specified, the standard built-in properties of global objects have the properties {[[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}.

The global object does not have [[Construct]] internal properties; the global object cannot be called as a constructor using the new operator.

The global object does not have [[Call]] internal properties, and the global object cannot be called as a function.

The [[Prototype]] and [[Class]] internal property values ​​of global objects are implementation-dependent.

In addition to the properties defined by this specification, global objects can also have additional host-defined properties. A global object can contain a property whose value is the global object itself; for example, in the HTML Document Object Model, the global object's window property is the global object itself.

Object Object

Call the Object constructor as a function

Treat Object as a function to call instead of a constructor, it performs a type conversion.

Object ( [ value ] )

When calling the Object function with a parameter value or no parameters, use the following steps:

  • If value is null, undefined or unspecified, create and return a A new Object object, which is the same as the result of calling the standard built-in Object constructor (15.2.2.1) with the same parameters.

  • Return ToObject(value).

Object Constructor

When Object is part of a new expression call, it is a constructor that creates an object.

new Object ( [ value ] )

When calling the Object constructor with a parameter value or no parameters, use the following steps:

  • If value is provided, then if Type(value) is Object, then if value is a native ECMAScript object, no new object is created, and value is simply returned. If value is a host object, actions are taken and implementation-dependent The method of the result can depend on the host object. If Type(value) is String, return ToObject(value). If Type(value) is Boolean, return ToObject(value). If Type(value) is Number, return ToObject( value).

  • Assertion: The parameter value is not provided or its type is Null or Undefined.

  • Let obj be a newly created native ECMAScript Object.

  • Set the [[Prototype]] internal property of obj to the standard built-in Object prototype object (15.2.4).

  • Set the [[Class]] internal property of obj to "Object".

  • Set the [[Extensible]] internal property of obj to true.

  • Set all internal methods specified in 8.12 of obj

  • Return obj.

Function object

Call Function constructor as a function

When a Function is called as a function, rather than as a constructor, it creates and initializes a New function object. So the function call Function(…) creates the same object as the new Function(…) expression with the same parameters.

Function (p1, p2, … , pn, body)

When calling the Function function with p1, p2, …, pn, body as parameters (n here can be 0, that is to say, there is no "p" parameter, and the body does not need to be provided at this time), use The following steps:

  • Create and return a new function object, as if it were created with the same parameters to the standard built-in constructor Function (15.3.2.1). Use a new expression.

Function constructor

When a Function is called as part of a new expression, it is a constructor: it initializes the newly created object.

new Function (p1, p2, … , pn, body)

The last parameter is specified as the body (executable code) of the function; any previous parameters are specified as formal parameters.

When calling the Function constructor with p1, p2, …, pn, body as parameters (n here can be 0, which means there is no "p" parameter, and body does not need to be provided at this time), use The following steps:

  • 令 argCount 为传给这个函数调用的参数总数 .

  • 令 P 为空字符串 .

  • 如果 argCount = 0, 令 body 为空字符串 .

  • 否则如果 argCount = 1, 令 body 为那个参数 .

  • 否则 , argCount > 1令 firstArg 为第一个参数 .令 P 为 ToString(firstArg).令 k 为 2.只要 k 6c90cc38f36b104708bb7b8442e952f5。本规范里面的 JSON 交换格式会使用 RFC4627 里所描述的,以下两点除外:

    • ECMAScript JSON 文法中的顶级 JSONText 产生式是由 JSONValue 构成,而不是 RFC4627 中限制成的 JSONObject 或者 JSONArray。

    • 确认 JSON.parse 和 JSON.stringify 的实现,它们必须准确的支持本规范描述的交换格式,而不允许对格式进行删除或扩展。这一点要区别于 RFC4627,它允许 JSON 解析器接受 non-JSON 的格式和扩展。

     JSON 对象内部属性 [[Prototype]] 的值是标准内建的 Object 原型对象(15.2.4)。内部属性 [[Class]] 的值是“JSON”。内部属性 [[Extensible]] 的值设置为 true。

     JSON 对象没有内部属性 [[Construct]];不能把 JSON 对象当作构造器来使用 new 操作符。

     JSON 对象没有内部属性 [[Call]]; 不能把 JSON 对象当作函数来调用。

    Error 对象

    Error对象的实例在运行时遇到错误的情况下会被当做异常抛出。Error对象也可以作为用户自定义异常类的基对象。

    【相关推荐:javascript学习教程

The above is the detailed content of What are the built-in objects in ecmascript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn