Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the two properties of an object in js

Shulou Source: shulou.com Published: 2022-06-03 00:01:28 11月19日 Update

This article mainly introduces "what are the two attributes of objects in js". In daily operation, I believe that many people have doubts about what are the two attributes of objects in js. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts of "what are the two attributes of objects in js?" Next, please follow the editor to study!

1. The object has two kinds of properties, the ordinary data property and the accessor property.

2. Accessor properties are essentially functions for getting and setting values (you can intercept, filter, handle, and other operations to set or get properties), but from the external code, it looks like traditional properties.

Example

Const user = {name: "John", surname: "Smith", get fullName () {return `${this.name} ${this.surname}`;}, set fullName (value) {[this.name, this.surname] = value.split ('');},}; console.log (user.fullName); / / John Smithuser.fullName = 'test fullName';console.log (user.fullName) / / test fullName at this point, the study on "what are the two attributes of objects in js" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Attributes objects learning more help practical ordinary next code traditions functions examples data articles methods essence theory knowledge articles websites Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Microsoft macOS Docker Shulou Tech Info