Skip to content

definePropertyでconst変数を再現できるのでは? #244

Description

@na-trium-144
const foo = "hello";

Object.defineProperty(globalThis, "foo", {
  get() {
    return "hello";
  },
  set(newValue) {
    throw new TypeError("Assignment to constant variable.");
  },
  configurable: true,
  enumerable: true
});

に置き換えられるようにすれば、constの再現になる?

replの環境リセット機能がないので、再宣言 (const foo = "hello"; の再実行) については実際のNode.jsの挙動とは違って許可しないと使いづらくなる

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions