跳至內容

eslint/no-with 正確性

此規則預設為開啟。

此規則的作用

禁止使用 with 陳述式

為什麼這樣不好?

with 陳述式可能會有問題,因為它會將物件的成員加入到目前的範圍中,使得無法判斷區塊內的變數實際上是指向什麼。

範例

javascript
with (point) {
  r = Math.sqrt(x * x + y * y); // is r a member of point?
}

參考資料

以 MIT 許可證發布。