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

Example Analysis of object attributes and adding New attributes in JavaScript

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly shows you the "JavaScript object attributes and add new attributes of the sample analysis", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "JavaScript object attributes and add new attributes of the sample analysis" this article.

JavaScript object properties, adding new properties

You can add new properties to an existing object through a simple assignment.

Assuming that the person object already exists-then you can add new properties to it:

Example

Person.nationality = "English"

You cannot use reserved words as property names (or method names). Please use the JavaScript naming convention.

Delete attribut

The delete keyword removes the attribute from the object:

Example

Var person = {firstName: "Bill", lastName: "Gates", age:62, eyeColor: "blue"}

Delete person.age; / / or delete person ["age"]

The delete keyword deletes both the value of the attribute and the attribute itself.

After the deletion, the property cannot be used until it is added back.

The delete operator is designed for object properties. It has no effect on variables or functions.

The delete operator should not be used for predefined JavaScript object properties. Doing so crashes the application.

Attribute value

All properties have names. Besides, they're worth it.

Value is one of the properties of an attribute.

Other features include: enumerable, configurable, writable.

These features define how properties are accessed (readable or writable)? )

In JavaScript, all properties are readable, but only values are modifiable (only if the attribute is writable).

(ECMAScript 5 has methods to get and set all property properties)

Prototype attribute

JavaScript objects inherit the properties of their prototypes.

The delete keyword does not delete inherited attributes, but if you delete a prototype property, it affects all objects inherited from the prototype.

The above is all the content of the article "sample Analysis of object attributes and adding New attributes in JavaScript". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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: 0

*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