在JS对象中引用自身属性

时间:2019-06-14 07:37:57

标签: javascript

如何获得centerYcenterX这个对象“区域”。两者均返回NaN,因为this.leftthis.right返回NULL:

const area = {
  top: viewportHeight * 20 / 100,
  bottom: viewportHeight - (viewportHeight * 20 / 100),
  left: 300,
  right: (viewportWidth * 30 / 100) + 300,
  centerX: (this.left + this.right) / 2, // NaN
  centerY: (this.top + this.bottom) / 2, // NaN
};

0 个答案:

没有答案