Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the types of JavaScript objects

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "which types of JavaScript objects are there". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "which types of JavaScript objects".

Three types of JavaScript objects

Built-in object: an object or class defined by ECMAScript. For example, arrays, functions, dates, and regular expressions.

Host object: defined by the host environment embedded in the JavaScript interpreter. Such as HTMLElement

Custom objects: objects defined by a running JavaScript

Own attributes: attributes that are defined directly in the object

Inheritance properties: properties defined in the prototype object of an object

1. Create object

(1), object direct quantity

Var empty= {}; var point= {XRX 1pr YRO 1}

(2) create an object through new

The keyword new is followed by a function call, where the function is called the constructor

Var o=new Object (); / / var o = {}; function Person (name,age) {this.name=name; this.age=age;} var p=new Person ("John", 32)

(3), prototype

Except for each JavaScript object (null), it is associated with another prototype object, and each object inherits properties from the prototype.

All objects created by direct quantities have the same prototype object, and references to the prototype object can be obtained through Object.prototype.

The prototype of an object created with the new keyword is the prototype attribute value of the constructor. The prototype Array.prototype of new Array ().

There are few objects without prototypes such as Object.prototype, and all built-in constructors have a prototype that inherits from Object.prototype.

(4), Object.create ()

The Object.create () static function, with the first argument being the prototype of the object, can create an object without a prototype by passing in null.

Var o1=Object.create (null); var o2=Object.create (Object.prototype); / / var O2 = {}; 2. Query and setting of properties

The object is passed. Or [] operator to get the value of the attribute. JavaScript objects are associative arrays. Property does not return undefined, and cannot access the properties of the undefined object, otherwise an exception is thrown.

Var len = book & & book.subtitle & & book.subtitle.length

Delete attributes: the delete operator, which always returns true, and can only delete its own attributes.

Detection attribute

In operator: checking own and inherited properties

HasOwnProperty (): check your own properties

PropertyIsEnumerable (): checks its own properties and is enumerable

For/in enumeration properties

Getter and setter of the property

Attribute values in ECMAScript can be replaced by one or two methods, which are called "accessor properties" by getter or setter. Declare with the keywords set and get.

3. Properties of attribut

Attribute properties: writable, enumerable, configurable

An object called "attribute descriptor" is defined in ECMAScript, which represents the properties of the property.

The descriptors for data properties are: value, writeable, enumerable, and configurable

The descriptors for access properties are get, set, enumerable, and configurable

Returns a descriptor for a specific property of an object through a static method

Object.getOwnPropertyDescriptor ({xuan1}, "x")

Object.defineProperty

4. Three properties of the object

(1) the prototype attribute ES5 can be queried by passing objects in Obejct.getPropertyOf (), which can be obtained by o.constructor.prototype. P.isPropertyOf (o) detects whether p is a prototype of o. (2) the class attribute of a class attribute object refers to a string that represents the type information of the object.

Function classof (o) {if (o = null) return "Null"; if (o = undefined) return "Undefined"; return Object.prototype.toString (o) .slice

(3) the extensibility of the extensible object indicates whether new attributes can be added to the object. All built-in and custom objects are shown to be extensible, and the extensibility of host objects is defined by the JavaScript engine.

Thank you for your reading, the above is the content of "which types of JavaScript objects", after the study of this article, I believe you have a deeper understanding of what types of JavaScript objects there are, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 278

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report