
1、对象有两种属性,普通的数据属性和访问器属性。
2、访问器属性本质上是用于获取和设置值的函数(可以拦截、过滤、处理等操作要设置或获取的属性),但从外部代码来看就像传统属性一样。
实例
constuser={
name:"John",
surname:"Smith",
getfullName(){
return`${this.name}${this.surname}`;
},
setfullName(value){
[this.name,this.surname]=value.split('');
},
};
console.log(user.fullName);//JohnSmith
user.fullName='testfullName';
console.log(user.fullName);//testfullName原文来自:https://www.py.cn © 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END

















































暂无评论内容