Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbol.unscopables #88

Open
sedationh opened this issue Jul 4, 2024 · 0 comments
Open

Symbol.unscopables #88

sedationh opened this issue Jul 4, 2024 · 0 comments

Comments

@sedationh
Copy link
Owner

Symbol.unscopables 是 ES6 引入的一个特殊的内置符号,用于指定在 with 语句块中哪些属性是不可见的。换句话说,它定义了对象中在 with 语句作用域中被排除的属性。

const obj = {
  foo: 1,

  bar: 2,

  [Symbol.unscopables]: {
    foo: true, // foo 属性在 with 语句中不可见
  },
};

with (obj) {
  console.log(foo); // ReferenceError: foo is not defined

  console.log(bar); // 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant