javascript对象属性get/set读取设置器

  标准浏览器和IE9+,javascript对象支持如面向对象语言的属性get(获取属性值)/set(设置属性值)设置器。示例代码如下

<script>
    var o = {get Version(){return this.version;},set Version(v){this.version=v}}
    o.version='2.0';
    alert(o.version)
</script>

  浏览器支持

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1 2.0 (1.8.1) 9 9.5 3
Computed property names Not supported 34 (34) Not supported Not supported Not supported

详情:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get

加支付宝好友偷能量挖...


原创文章,转载请注明出处:javascript对象属性get/set读取设置器

评论(0)Web开发网
阅读(133)喜欢(0)JavaScript/Ajax开发技巧