Skip to content

Commit 9612a31

Browse files
chorom-hamyeonjuanbumkeyy
authored
Issue171 short circuiting assignment operators translation (#205)
* Translate ts4.0 Short-Circuiting Assignment Operators * Update ts4.0 Short-Circuiting Assignment Operators * Update pages/release-notes/typescript-4.0.md Co-authored-by: YeonJuan <yeonjuan93@naver.com> * Update pages/release-notes/typescript-4.0.md Co-authored-by: Kibeom Kwon <kgbum2222@gmail.com> Co-authored-by: YeonJuan <yeonjuan93@naver.com> Co-authored-by: Kibeom Kwon <kgbum2222@gmail.com>
1 parent f96dcb0 commit 9612a31

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

Diff for: โ€Žpages/release-notes/typescript-4.0.md

+27-27
Original file line numberDiff line numberDiff line change
@@ -338,79 +338,79 @@ class Square {
338338

339339
๋” ์ž์„ธํžˆ ์•Œ๊ณ  ์‹ถ๋‹ค๋ฉด, [์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋Š” Pull Request๋ฅผ ๋ณด์„ธ์š”](https://github.com/microsoft/TypeScript/pull/379200).
340340

341-
## Short-Circuiting Assignment Operators
341+
## ๋‹จ์ถ• ํ• ๋‹น ์—ฐ์‚ฐ์ž (Short-Circuiting Assignment Operators)
342342

343-
JavaScript, and a lot of other languages, support a set of operators called _compound assignment_ operators.
344-
Compound assignment operators apply an operator to two arguments, and then assign the result to the left side.
345-
You may have seen these before:
343+
JavaScript์™€ ๋งŽ์€ ์–ธ์–ด๋Š” _๋ณตํ•ฉ ํ• ๋‹น (compound assignment)_ ์—ฐ์‚ฐ์ž๋ผ๊ณ  ๋ถˆ๋ฆฌ๋Š” ์—ฐ์‚ฐ์ž ์ง‘ํ•ฉ์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
344+
๋ณตํ•ฉ ํ• ๋‹น ์—ฐ์‚ฐ์ž๋Š” ๋‘ ๊ฐœ์˜ ์ธ์ˆ˜์— ์—ฐ์‚ฐ์ž๋ฅผ ์ ์šฉํ•œ ๋‹ค์Œ ๊ฒฐ๊ณผ๋ฅผ ์™ผ์ชฝ์— ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค.
345+
์ด์ „์— ์•„๋ž˜์™€ ๊ฐ™์€ ๊ฒƒ์„ ๋ณธ ์ ์ด ์žˆ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค:
346346

347347
```ts
348-
// Addition
348+
// ๋ง์…ˆ
349349
// a = a + b
350350
a += b;
351351

352-
// Subtraction
352+
// ๋บ„์…ˆ
353353
// a = a - b
354354
a -= b;
355355

356-
// Multiplication
356+
// ๊ณฑ์…ˆ
357357
// a = a * b
358358
a *= b;
359359

360-
// Division
360+
// ๋‚˜๋ˆ—์…ˆ
361361
// a = a / b
362362
a /= b;
363363

364-
// Exponentiation
364+
// ์ง€์ˆ˜ํ™”
365365
// a = a ** b
366366
a **= b;
367367

368-
// Left Bit Shift
368+
// ์™ผ์ชฝ ๋น„ํŠธ ์‹œํ”„ํŠธ
369369
// a = a << b
370370
a <<= b;
371371
```
372372

373-
So many operators in JavaScript have a corresponding assignment operator!
374-
Up until recently, however, there were three notable exceptions: logical _and_ (`&&`), logical _or_ (`||`), and nullish coalescing (`??`).
373+
JavaScript์˜ ๋งŽ์€ ์—ฐ์‚ฐ์ž์— ์œ„์™€ ๊ฐ™์€ ํ• ๋‹น ์—ฐ์‚ฐ์ž๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค!
374+
๊ทธ๋Ÿฌ๋‚˜ ์ตœ๊ทผ๊นŒ์ง€๋„ ๋…ผ๋ฆฌ _and_ ์—ฐ์‚ฐ์ž (`&&`), ๋…ผ๋ฆฌ _or_ ์—ฐ์‚ฐ์ž (`||`) ๋ฐ null๊ณผ ๊ฐ™์€ ๊ฒƒ์„ ๋ณ‘ํ•ฉํ•˜๋Š” ์—ฐ์‚ฐ์ž (nullish coalescing) (`??`)์˜ ์„ธ ๊ฐ€์ง€ ์ฃผ๋ชฉํ• ๋งŒํ•œ ์˜ˆ์™ธ๊ฐ€ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.
375375

376-
That's why TypeScript 4.0 supports a new ECMAScript feature to add three new assignment operators: `&&=`, `||=`, and `??=`.
376+
์ด๊ฒƒ์ด TypeScript 4.0์ด ์ƒˆ๋กœ์šด ํ• ๋‹น ์—ฐ์‚ฐ์ž`&&=`,`||=`๋ฐ`??=`๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ์ƒˆ๋กœ์šด ECMAScript ๊ธฐ๋Šฅ์„ ์ง€์›ํ•˜๋Š” ์ด์œ ์ž…๋‹ˆ๋‹ค.
377377

378-
These operators are great for substituting any example where a user might write code like the following:
378+
์ด๋Ÿฌํ•œ ์—ฐ์‚ฐ์ž๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ๋ชจ๋“  ์˜ˆ๋ฅผ ๋Œ€์ฒดํ•˜๋Š” ๋ฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
379379

380380
```ts
381381
a = a && b;
382382
a = a || b;
383383
a = a ?? b;
384384
```
385385

386-
Or a similar `if` block like
386+
ํ˜น์€ ์•„๋ž˜์™€ ๋น„์Šทํ•œ `if` ๋ธ”๋ก
387387

388388
```ts
389-
// could be 'a ||= b'
389+
// 'a ||= b'๋กœ ๋Œ€์ฒด ๊ฐ€๋Šฅ
390390
if (!a) {
391391
a = b;
392392
}
393393
```
394394

395-
There are even some patterns we've seen (or, uh, written ourselves) to lazily initialize values, only if they'll be needed.
395+
์šฐ๋ฆฌ๊ฐ€ ๋ณธ(ํ˜น์€ ์ง์ ‘ ์ž‘์„ฑํ•œ) ์ฝ”๋“œ ํŒจํ„ด ์ค‘ ํ•„์š”ํ•œ ๊ฒฝ์šฐ์—๋งŒ ๊ฐ’์„ ์ง€์—ฐ ์ดˆ๊ธฐํ™”์‹œํ‚ค๊ธฐ ์œ„ํ•œ ํŒจํ„ด๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
396396

397397
```ts
398398
let values: string[];
399399
(values ?? (values = [])).push("hello");
400400

401-
// After
401+
// ์ดํ›„
402402
(values ??= []).push("hello");
403403
```
404404

405-
(look, we're not proud of _all_ the code we write...)
405+
(๋ณด์„ธ์š”, ์šฐ๋ฆฌ๊ฐ€ ์ž‘์„ฑํ•œ _๋ชจ๋“ _ ์ฝ”๋“œ๊ฐ€ ์ž๋ž‘์Šค๋Ÿฌ์šด ๊ฒƒ์€ ์•„๋‹™๋‹ˆ๋‹ค...)
406406

407-
On the rare case that you use getters or setters with side-effects, it's worth noting that these operators only perform assignments if necessary.
408-
In that sense, not only is the right side of the operator "short-circuited" - the assignment itself is too.
407+
๋“œ๋ฌผ์ง€๋งŒ ๋ถ€์ˆ˜ ํšจ๊ณผ(side-effects)๊ฐ€ ์žˆ๋Š” getter ๋˜๋Š” setter๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ์ด๋Ÿฌํ•œ ์—ฐ์‚ฐ์ž๊ฐ€ ํ•„์š”ํ•œ ๊ฒฝ์šฐ์—๋งŒ ํ• ๋‹น์„ ์ˆ˜ํ–‰ํ•œ๋‹ค๋Š” ์ ์— ์œ ์˜ํ•  ํ•„์š”๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
408+
๊ทธ๋Ÿฐ ์˜๋ฏธ์—์„œ ์—ฐ์‚ฐ์ž์˜ ์˜ค๋ฅธ์ชฝ์ด "๋‹จ์ถ• (short-circuited)"๋  ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ํ• ๋‹น ์ž์ฒด๋„ ๋งˆ์ฐฌ๊ฐ€์ง€์ž…๋‹ˆ๋‹ค.
409409

410410
```ts
411411
obj.prop ||= foo();
412412

413-
// roughly equivalent to either of the following
413+
// ๋‹ค์Œ ์ค‘ ํ•˜๋‚˜์™€ ๋Œ€๋žต ๋™์ผํ•จ
414414

415415
obj.prop || (obj.prop = foo());
416416

@@ -419,14 +419,14 @@ if (!obj.prop) {
419419
}
420420
```
421421

422-
[Try running the following example](https://www.typescriptlang.org/play?ts=Nightly#code/MYewdgzgLgBCBGArGBeGBvAsAKBnmA5gKawAOATiKQBQCUGO+TMokIANkQHTsgHUAiYlChFyMABYBDCDHIBXMANoBuHI2Z4A9FpgAlIqXZTgRGAFsiAQg2byJeeTAwAslKgSu5KWAAmIczoYAB4YAAYuAFY1XHwAXwAaWxgIEhgKKmoAfQA3KXYALhh4EA4iH3osWM1WCDKePkFUkTFJGTlFZRimOJw4mJwAM0VgKABLcBhB0qCqplr63n4BcjGCCVgIMd8zIjz2eXciXy7k+yhHZygFIhje7BwFzgblgBUJMdlwM3yAdykAJ6yBSQGAeMzNUTkU7YBCILgZUioOBIBGUJEAHwxUxmqnU2Ce3CWgnenzgYDMACo6pZxpYIJSOqDwSkSFCYXC0VQYFi0NMQHQVEA) to see how that differs from _always_ performing the assignment.
422+
[๋‹ค์Œ ์˜ˆ์‹œ๋ฅผ ์‹คํ–‰ํ•ด๋ณด์„ธ์š”](https://www.typescriptlang.org/play?ts=Nightly#code/MYewdgzgLgBCBGArGBeGBvAsAKBnmA5gKawAOATiKQBQCUGO+TMokIANkQHTsgHUAiYlChFyMABYBDCDHIBXMANoBuHI2Z4A9FpgAlIqXZTgRGAFsiAQg2byJeeTAwAslKgSu5KWAAmIczoYAB4YAAYuAFY1XHwAXwAaWxgIEhgKKmoAfQA3KXYALhh4EA4iH3osWM1WCDKePkFUkTFJGTlFZRimOJw4mJwAM0VgKABLcBhB0qCqplr63n4BcjGCCVgIMd8zIjz2eXciXy7k+yhHZygFIhje7BwFzgblgBUJMdlwM3yAdykAJ6yBSQGAeMzNUTkU7YBCILgZUioOBIBGUJEAHwxUxmqnU2Ce3CWgnenzgYDMACo6pZxpYIJSOqDwSkSFCYXC0VQYFi0NMQHQVEA) ์˜ˆ์‹œ๋ฅผ ํ†ตํ•ด _ํ•ญ์ƒ_ ํ• ๋‹น์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ฒƒ๊ณผ ์–ด๋–ป๊ฒŒ ๋‹ค๋ฅธ์ง€ ํ™•์ธํ•ด๋ณด์„ธ์š”.
423423

424424
```ts
425425
const obj = {
426426
get prop() {
427427
console.log("getter has run");
428428

429-
// Replace me!
429+
// ์ด๊ณณ์„ ๋ฐ”๊ฟ”๋ณด์„ธ์š”!
430430
return Math.random() < 0.5;
431431
},
432432
set prop(_val: boolean) {
@@ -446,10 +446,10 @@ console.log("This one *sometimes* runs the setter");
446446
obj.prop ||= foo();
447447
```
448448

449-
We'd like to extend a big thanks to community member [Wenlu Wang](https://github.com/Kingwl) for this contribution!
449+
๊ธฐ์—ฌํ•ด์ฃผ์‹  ์ปค๋ฎค๋‹ˆํ‹ฐ ๋ฉค๋ฒ„ [Wenlu Wang](https://github.com/Kingwl) ๋‹˜์—๊ฒŒ ํฐ ๊ฐ์‚ฌ๋ฅผ ํ‘œํ•ฉ๋‹ˆ๋‹ค.
450450

451-
For more details, you can [take a look at the pull request here](https://github.com/microsoft/TypeScript/pull/37727).
452-
You can also [check out TC39's proposal repository for this feature](https://github.com/tc39/proposal-logical-assignment/).
451+
๋” ์ž์„ธํ•œ ๋‚ด์šฉ์„ ๋ณด๊ณ  ์‹ถ์œผ์‹œ๋‹ค๋ฉด [์ด ํ’€ ๋ฆฌํ€˜์ŠคํŠธ๋ฅผ ํ™•์ธํ•ด๋ณด์„ธ์š”](https://github.com/microsoft/TypeScript/pull/37727).
452+
[TC39 ์ œ์•ˆ ์ €์žฅ์†Œ์—์„œ๋„ ์ด ๊ธฐ๋Šฅ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.](https://github.com/tc39/proposal-logical-assignment/).
453453

454454
## `unknown` on `catch` Clause Bindings
455455

0 commit comments

Comments
ย (0)