JS的get和set使用示例
2018-10-12 13:55
351 查看
巧用get和set,能够直接操作对象属性实现读写,可以极大的提高编程效率,给出一个典型示例:
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
您可能感兴趣的文章:
相关文章推荐
- JS的get和set使用示例
- JS的get和set使用示例
- 使用SetWindowLongPtr与GetWindowLongPtr的问题
- 下面的代码示例使用 BeginGetRequestStream 方法对流实例发出异步请求。
- 通过 @Autowired的使用来消除 set ,get方法 ---- Spring · JPA ·hibernate 的使用方法
- 反射类的使用ReflectUtil(设置set和获取get某个类属性值)
- 使用'VRM_SET_VALUES'函数在selection屏幕上建一个Combobox控件示例
- 看点:response对象,setContentType(String type)方法的使用示例。
- js里的prototype使用示例
- js eval使用示例
- InternetSetCookieEx和InternetGetCookieEx使用tip(COOKIE文件格式)
- 慎重使用Get/Set成员函数(一)问题的提出
- 不用框架使用ajax 纯js使用ajax post,get范例及其区别
- 使用SPA/GPA 参数--SAP内存参数设置&SET /GET PARAMTER ID
- 注解的力量 -----Spring 2.5 JPA hibernate 使用方法的点滴整理(三):通过 @Autowired的使用来消除 set ,get方法。
- JSP使用get/setProperty时,Bean的scope 改变引起的问题
- 使用'VRM_SET_VALUES'函数在selection屏幕上建一个Combobox控件示例
- Get the average socre of the student.(The exmaple of group, having and order by).求学生平均分(group, having 和 order by使用示例).
- InternetSetCookieEx和InternetGetCookieEx使用tip(COOKIE文件格式)
- 使用'VRM_SET_VALUES'函数在selection屏幕上建一个Combobox控件示例