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

fix: prototypeを表すのに # を使わないようにする #1382

Merged
merged 17 commits into from
Feb 6, 2022
Merged

fix: prototypeを表すのに # を使わないようにする #1382

merged 17 commits into from
Feb 6, 2022

Conversation

azu
Copy link
Collaborator

@azu azu commented Feb 5, 2022

#1368 # はES2022以降だと別の意味を持つのでprototypeの意味には使わないようにする。

基本ルール

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

変更点

  • textlintのルールを追加
  • "prototypeの短縮表記の # について"を書き換える(単純に消すぐらいな気がする)
  • コラムとして 短縮表記の # についてを入れる(昔はよく#がprototypeの意味として使われてた的な話)
  • 全体的に文章を見直し

fix #1368

@bot-user
Copy link

bot-user commented Feb 5, 2022

✔️ Deploy Preview for js-primer ready!

🔨 Explore the source changes: 43d8f53

🔍 Inspect the deploy log: https://app.netlify.com/sites/js-primer/deploys/61ff3007fbcaca0008c7ab93

😎 Browse the preview: https://deploy-preview-1382--js-primer.netlify.app

@asciidwango asciidwango deleted a comment from bot-user Feb 5, 2022
@azu azu requested a review from lacolaco February 5, 2022 12:05
"no-use-prototype-hash": {
"allow": [
// CSSセレクタの表現であるため許可
"div#result"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これだけ例外

@@ -21,6 +21,12 @@ module.exports = {
},
"no-use-column": true,
"footnote-order": true,
"no-use-prototype-hash": {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

textlintルールで、\w+#\w+ は基本的に禁止している。

getterやsetterを利用しないと実現が難しいものとして`Array#length`プロパティがあります。
`Array#length`プロパティへ値を代入すると、そのインデックス以降の要素は自動的に削除される仕様になっています。
getterやsetterを利用しないと実現が難しいものとして`Array.prototype.length`プロパティがあります。
Arrayの`length`プロパティへ値を代入すると、そのインデックス以降の要素は自動的に削除される仕様になっています。
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この章だけ prototype 自体の解説してるので、短縮表記自体(Arrayのincludesメソッドパターン)を使わなくしてる部分がある。
修正し切れてない部分がありそうなので要チェック。


このインスタンスから`prototype`オブジェクト上に定義されたメソッドを参照できる仕組みを**プロトタイプチェーン**と呼びます。
プロトタイプチェーンの仕組みについては「[クラス][]」の章で扱うため、ここではインスタンスからプロトタイプメソッドを呼び出せるということがわかっていれば問題ありません。

<!-- textlint-disable no-use-prototype-hash,ja-technical-writing/sentence-length -->

### [コラム] `Object#toString`という短縮した表記について {#prototype-shorthand-syntax}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

追加したコラム。

@@ -46,15 +46,13 @@ console.log(typeof Object.prototype.toString); // => "function"
```

このような`prototype`オブジェクトに組み込まれているメソッドは**プロトタイプメソッド**と呼ばれます。
この書籍では`Object.prototype.toString`のようなプロトタイプメソッドを`Object#toString`と短縮して表記します。
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここ削除した。

@@ -214,8 +214,8 @@ Unicodeでは1文字を表すのに使う最小限のビットの組み合わせ
-->

次のコードは、文字列を構成するCode Unitをhex値(16進数)にして表示する例です。
`String#charCodeAt`メソッドは、文字列の指定インデックスのCode Unitを整数として返します。
そのCode Unitの整数値を`Number#toString`メソッドでhex値(16進数)にしています。
Stringの`charCodeAt`メソッドは、文字列の指定インデックスのCode Unitを整数として返します。
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stringの章 書き直しが多いので要チェック。

Stringの~~~メソッド みたいなのが連発してたので、「Stringの」の部分も削ってる箇所が結構ある。

@@ -529,7 +529,7 @@ console.log(array.join(", ")); // => "1, 2, , , "

-->

`ArrayLike#length`のsetterで要素の追加や削除を実装することで、配列のような`length`プロパティを実装できます。
ArrayLikeの`length`プロパティのsetterで要素の追加や削除を実装することで、配列のような`length`プロパティを実装できます。
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここなんか変かも。

Copy link
Collaborator

@lacolaco lacolaco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一点だけコメントしました

azu and others added 2 commits February 6, 2022 10:15
Co-authored-by: Suguru Inatomi <suguru.inatomi@gmail.com>
source/basic/class/README.md Outdated Show resolved Hide resolved
source/basic/prototype-object/README.md Outdated Show resolved Hide resolved
source/basic/prototype-object/README.md Outdated Show resolved Hide resolved
source/basic/prototype-object/README.md Outdated Show resolved Hide resolved
@@ -1020,11 +1020,11 @@ console.log(str.replace(/にわ/, "niwa")); // => "niwaにはにわにわとり
console.log(str.replace(/にわ/g, "niwa")); // => "niwaにはniwaniwaとりがいる"
```

文字列から検索文字列にマッチするものをすべて置換する場合には、ES2021で追加された`String#replaceAll`メソッドも利用できます。
`String#replace`メソッドでは、最初に一致したものだけが置換されますが、`String#replaceAll`メソッドでは一致したものがすべて置換されます。
文字列から検索文字列にマッチするものをすべて置換する場合には、ES2021で追加されたStringの`replaceAll`メソッドも利用できます。
Copy link
Collaborator Author

@azu azu Feb 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

タイトル的なのでString.prototype.replaceAllでもいいかなー
結構他の所も多いか。

source/use-case/todoapp/update-delete/README.md Outdated Show resolved Hide resolved
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

Successfully merging this pull request may close these issues.

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