2
難以弄清楚爲什麼Material-UI會爲其Popover設置一個等於它自己的變量。在Material-UI中,他們爲什麼要將這個變量設置爲自己?
下面是代碼片段檢查返回前的兩個塊。
設置t.vertical = t.vertical;
的目的是什麼?
getPositions(anchor, target) {
const a = {...anchor};
const t = {...target};
const positions = {
x: ['left', 'right'].filter((p) => p !== t.horizontal),
y: ['top', 'bottom'].filter((p) => p !== t.vertical),
};
const overlap = {
x: this.getOverlapMode(a.horizontal, t.horizontal, 'middle'),
y: this.getOverlapMode(a.vertical, t.vertical, 'center'),
};
positions.x.splice(overlap.x === 'auto' ? 0 : 1, 0, 'middle');
positions.y.splice(overlap.y === 'auto' ? 0 : 1, 0, 'center');
if (overlap.y !== 'auto') {
a.vertical = a.vertical === 'top' ? 'bottom' : 'top';
if (overlap.y === 'inclusive') {
t.vertical = t.vertical; // HERE
}
}
if (overlap.x !== 'auto') {
a.horizontal = a.horizontal === 'left' ? 'right' : 'left';
if (overlap.y === 'inclusive') {
t.horizontal = t.horizontal; // HERE
}
}
return {
positions: positions,
anchorPos: a,
};
}
如果'vertical'是一個具有getter/setter邏輯的屬性,那麼該賦值可能有副作用。 – Dai
我用'Object.getOwnPropertyDescriptor(obj,「foo」)。get;'來檢查 - 看起來不像getter/setter。 – JordanHendrix