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

ES2022: prototypeを表すのに # を使うべきかどうか #1368

Closed
azu opened this issue Dec 30, 2021 · 6 comments · Fixed by #1382
Closed

ES2022: prototypeを表すのに # を使うべきかどうか #1368

azu opened this issue Dec 30, 2021 · 6 comments · Fixed by #1382

Comments

@azu
Copy link
Collaborator

azu commented Dec 30, 2021

ES2022のクラスに # が導入される。

なので # はPrivate Fieldsを意味するように見える。

class MyClass {
  #method = () => {
     console.log("private method")
  } 
}

MyClass#method と書いてしまうと、MyClass.prototype.methodMyClassのprivate #methodのことかが区別できなくなる。(📝 実際には this.#method としてアクセスするので、.# となるけど、表現的に紛らわしいのは同じ)

そのため、Array#includes みたいに prototypeを表す記号として # を使うのは、避けたほうがいい可能性が高い。

変更後の基本ルール

  • セクションタイトル:
    • 正式名称の 「Array.prototype.includes メソッド 」を使う
  • 文中
    • prototoypeメソッドは、「Arrayのincludesメソッド」を使う
    • 静的メソッドの場合は、「 Array.from 静的メソッド 」と言うことで区別する
    • プロパティの場合は、「Objectの a プロパティ」という表現
    • Class Fieldは メンバー と呼ぶ感じで、プロパティと区別 まだ未定
  • 例外
    • CSSセレクタでのID指定: div#result はlintのオプションで例外としてる

やるべきこと

  • # を prototype に置き換える
  • この記法の紹介は消す
  • 代わりに、prototypeの紹介の時に、# がprototypeを表す記号として使われていることがあったと言うコラムをたす
    • この書籍からは # === prototype は取り除くけど、他の文章でも使われてること多い

@lacolaco どうですかね?

@azu
Copy link
Collaborator Author

azu commented Dec 30, 2021

https://zenn.dev/qnighy/articles/3a999fdecc3e81#comment-aaac501b3562a4
# が示していたものは、
prototype or インスタンスのプロパティにあたるFields #1364
の2つがある。
なので、それぞれ別々に使い分ける必要性があるのかなー

@azu
Copy link
Collaborator Author

azu commented Jan 18, 2022

@azu
Copy link
Collaborator Author

azu commented Jan 18, 2022

要検証ではあるけど、次のようなイメージ

  • タイトルは正式名称の Array.prototype.includes メソッド
  • 内部では、 Array の includes メソッド
    • 静的メソッドの場合は、 Array.from 静的メソッド と言うことで区別できる
    • プロパティにも # を使ってるケースあるので Objの a プロパティ的な表現
    • Class Fieldは メンバー と呼ぶ感じで、プロパティと区別

@lacolaco
Copy link
Collaborator

lacolaco commented Jan 19, 2022

内部では、 Array の includes メソッド

これに賛成です。 毎回 "Arrayインスタンスの" と書くのは冗長すぎるかなと。

@azu
Copy link
Collaborator Author

azu commented Feb 5, 2022

https://jsprimer.net/use-case/todoapp/

div#result というCSSセレクタのパターンもあったことに気づいた。
でもこれは # 自体に IDセレクタの意味があるから、そういう説明するしかないか。
textlintルールでいまいち制御できなくて不便だな

@azu
Copy link
Collaborator Author

azu commented Feb 5, 2022

#1382 で変更をまとめてした

@azu azu closed this as completed in #1382 Feb 6, 2022
@azu azu mentioned this issue Feb 6, 2022
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants