function AAA(options){
this._name = options.name || 'haha'
}
Object.defineProperties(AAA.prototype,{
name:{
get:function(){
return this._name;
},
set:function(value){
this._name = value;
}
}
})
AAA.prototype.showName = function (){
alert(this._name)
}
// export default AAA;
let aaa=new AAA({name:'111'});
aaa.name = 'ccc'
aa.showName()
js class
最新推荐文章于 2022-06-12 12:07:36 发布
本文介绍了如何使用JavaScript创建函数AAA,并通过Object.defineProperties动态设置和获取name属性。通过实例展示如何创建对象并修改其name属性,以及调用showName方法显示名称。
摘要由CSDN通过智能技术生成