js-getter的使用

来源:互联网 发布:mac安装cocoapods 编辑:程序博客网 时间:2024/05/29 14:11

getter使用

var obj = {  log: ['example','test'],  get latest() {    if (this.log.length == 0) return undefined;    return this.log[this.log.length - 1];  }}console.log(obj.latest); // "test".