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

js destructuring assignment bug

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;
}


posted @ 2020-03-09 16:40  xgqfrms  阅读(126)  评论(2编辑  收藏  举报