源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

JS的get和set使用示例

  • 时间:2022-01-22 01:22 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:JS的get和set使用示例
巧用get和set,能够直接操作对象属性实现读写,可以极大的提高编程效率,给出一个典型示例:
[u]复制代码[/u] 代码如下:
var test = { _Name : null, _Age : 0, //_Name的读写 set name(name) {this._Name = name;}, get name() {return this._Name;}, //_Age的读写 set age(age) {this._Age = age;}, get age() {return this._Age;} } alert(test.name + " " + test.age);//bull 0 test.name = 'lucy'; test.age = 20; alert(test.name + " " + test.age);//lucy 20
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部