JS的get和set使用示例

时间:2014-02-20    点击:75   
巧用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控制浏览器全屏示例代码
JS去掉第一个字符和最后一个字符的实现代码
js动态创建上传表单通过iframe模拟Ajax实现无刷新
JS中数组Array的用法示例介绍
javascript的回调函数应用示例
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved