Skip to content

Commit 27457f7

Browse files
committed
レビュー反映
1 parent 6947a7e commit 27457f7

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

docs/3-web-servers/04-server/index.mdx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,15 @@ console.log(["Apple", "Banana", "Orange"].join("/")); // Apple/Banana/Orange
200200
[`String#replace`](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/replace) メソッドは、第一引数に与えられた文字列 (または[正規表現](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/RegExp)) に一致する文字列を第二引数の文字列に置き換えた新しい文字列を返します。
201201
第一引数が文字列の場合は、最初に一致した場所のみを置き換えます。
202202
一致するすべての場所を置き換えたい場合は、代わりに [`String#replaceAll`](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll) を使います。
203-
どちらのメソッドも、元の文字列は変更されません。
204203

205204
```js
206205
const base = "ABCBCC";
207206
document.write(base.replace("BC", "EFG")); // AEFGBCC
208207
document.write(base.replaceAll("C", "T")); // ABTBTT
208+
document.write(base); // ABCBCC (元の文字列は変更されない)
209209
```
210210

211-
これと `fs.readFileSync` 関数を用いることで、HTML を別のファイルに分けて保存することができるようになり、より簡単に管理することができます。
211+
`String#replace` `fs.readFileSync` 関数を用いることで、HTML を別のファイルに分けて保存することができるようになり、より簡単に管理することができます。
212212

213213
```html title="index.html"
214214
<!doctype html>
@@ -233,9 +233,9 @@ const app = express();
233233

234234
const names = ["田中", "鈴木", "佐藤"];
235235
app.get("/", (request, response) => {
236-
const index = fs.readFileSync("./index.html", "utf-8");
236+
const template = fs.readFileSync("./index.html", "utf-8");
237237
const namesAsHTML = names.map((user) => `<li>${user}</li>`).join("");
238-
const html = index.replace("{users}", namesAsHTML);
238+
const html = template.replace("{users}", namesAsHTML);
239239
response.send(html);
240240
});
241241

@@ -316,4 +316,3 @@ app.listen(3000);
316316
解答例 2:
317317

318318
<ViewSource url={import.meta.url} path="_samples/server-or-client" />
319-
````

0 commit comments

Comments
 (0)