📜  js 对象获取器 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:03.554000             🧑  作者: Mango

代码示例1
const obj = {
  log: ['a', 'b', 'c'],
  get latest() {
    if (this.log.length === 0) {
      return undefined;
    }
    return this.log[this.log.length - 1];
  }
};

console.log(obj.latest);
// expected output: "c"