1、对象有两种属性,普通的数据属性和访问器属性。
2、访问器属性本质上是用于获取和设置值的函数(可以拦截、过滤、处理等操作要设置或获取的属性),但从外部代码来看就像传统属性一样。
实例
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 Smith user.fullName = 'test fullName'; console.log(user.fullName); // test fullName
以上就是js中对象的两种属性,希望对大家有所帮助。更多js学习指路:
Copyright © 2019- net188.cn 版权所有 湘ICP备2022005869号-2
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务