Example Analysis of object attributes and adding New attributes in JavaScript
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!