📜  js 对象 - 任何代码示例

📅  最后修改于: 2022-03-11 14:57:32.444000             🧑  作者: Mango

代码示例6
'use strict';

var obj = {
  a: 10
  b:20
};

Object.defineProperty(obj, 'b', {
  get: () => {
    console.log(this.a, typeof this.a, this); // undefined 'undefined' Window {...} (or the global object)
    return this.a + 10; // represents global object 'Window', therefore 'this.a' returns 'undefined'
  }
});