xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

js destructuring assignment bug

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment


const getShapeCenterPoint = (points = [], type = "object") => {
  // 设置旋转的 origin,为 polygon 的中心,旋转偏移量
  let [top, left, right, bottom] = ["", "", "", ""];
  // bug ???
  // points.forEach((type === "object" ? {x, y} : [x, y], i) => {
  // points.forEach(({x, y}, i) => {
  // points.forEach(([x, y], i) => {
  points.forEach(type === "object" ? {x, y} : [x, y], i => {
    if (i === 0) {
      top = y;
      bottom = y;
      left = x;
      right = x;
    } else {
      top = Math.min(top, y);
      bottom = Math.max(bottom, y);
      left = Math.min(left, x);
      right = Math.max(right, x);
    }
  });
  const point = {
    cx: (left + right) / 2,
    cy: (top + bottom) / 2,
  };
  return point;
}


原文地址:https://www.cnblogs.com/xgqfrms/p/12449524.html