@@ -338,79 +338,79 @@ class Square {
338
338
339
339
๋ ์์ธํ ์๊ณ ์ถ๋ค๋ฉด, [ ์ฝ๋๋ฅผ ์คํํ๋ Pull Request๋ฅผ ๋ณด์ธ์] ( https://github.com/microsoft/TypeScript/pull/379200 ) .
340
340
341
- ## Short-Circuiting Assignment Operators
341
+ ## ๋จ์ถ ํ ๋น ์ฐ์ฐ์ ( Short-Circuiting Assignment Operators)
342
342
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
+ ์ด์ ์ ์๋์ ๊ฐ์ ๊ฒ์ ๋ณธ ์ ์ด ์์ ๊ฒ์
๋๋ค :
346
346
347
347
``` ts
348
- // Addition
348
+ // ๋ง์
349
349
// a = a + b
350
350
a += b ;
351
351
352
- // Subtraction
352
+ // ๋บ์
353
353
// a = a - b
354
354
a -= b ;
355
355
356
- // Multiplication
356
+ // ๊ณฑ์
357
357
// a = a * b
358
358
a *= b ;
359
359
360
- // Division
360
+ // ๋๋์
361
361
// a = a / b
362
362
a /= b ;
363
363
364
- // Exponentiation
364
+ // ์ง์ํ
365
365
// a = a ** b
366
366
a * *= b ;
367
367
368
- // Left Bit Shift
368
+ // ์ผ์ชฝ ๋นํธ ์ํํธ
369
369
// a = a << b
370
370
a <<= b ;
371
371
```
372
372
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) (` ?? ` )์ ์ธ ๊ฐ์ง ์ฃผ๋ชฉํ ๋งํ ์์ธ๊ฐ ์์์ต๋๋ค .
375
375
376
- That's why TypeScript 4.0 supports a new ECMAScript feature to add three new assignment operators: ` &&= ` , ` ||= ` , and ` ??= ` .
376
+ ์ด๊ฒ์ด TypeScript 4.0์ด ์๋ก์ด ํ ๋น ์ฐ์ฐ์ ` &&= ` ,` ||= ` ๋ฐ ` ??= ` ๋ฅผ ์ถ๊ฐํ๋ ์๋ก์ด ECMAScript ๊ธฐ๋ฅ์ ์ง์ํ๋ ์ด์ ์
๋๋ค .
377
377
378
- These operators are great for substituting any example where a user might write code like the following:
378
+ ์ด๋ฌํ ์ฐ์ฐ์๋ ์ฌ์ฉ์๊ฐ ๋ค์๊ณผ ๊ฐ์ ์ฝ๋๋ฅผ ์์ฑํ ์ ์๋ ๋ชจ๋ ์๋ฅผ ๋์ฒดํ๋ ๋ฐ ์ ์ฉํฉ๋๋ค.
379
379
380
380
``` ts
381
381
a = a && b ;
382
382
a = a || b ;
383
383
a = a ?? b ;
384
384
```
385
385
386
- Or a similar ` if ` block like
386
+ ํน์ ์๋์ ๋น์ทํ ` if ` ๋ธ๋ก
387
387
388
388
``` ts
389
- // could be 'a ||= b'
389
+ // 'a ||= b'๋ก ๋์ฒด ๊ฐ๋ฅ
390
390
if (! a ) {
391
391
a = b ;
392
392
}
393
393
```
394
394
395
- There are even some patterns we've seen (or, uh, written ourselves) to lazily initialize values, only if they'll be needed .
395
+ ์ฐ๋ฆฌ๊ฐ ๋ณธ(ํน์ ์ง์ ์์ฑํ) ์ฝ๋ ํจํด ์ค ํ์ํ ๊ฒฝ์ฐ์๋ง ๊ฐ์ ์ง์ฐ ์ด๊ธฐํ์ํค๊ธฐ ์ํ ํจํด๋ ์์ต๋๋ค .
396
396
397
397
``` ts
398
398
let values: string [];
399
399
(values ?? (values = [])).push (" hello" );
400
400
401
- // After
401
+ // ์ดํ
402
402
(values ?? = []).push (" hello" );
403
403
```
404
404
405
- (look, we're not proud of _ all _ the code we write ...)
405
+ (๋ณด์ธ์, ์ฐ๋ฆฌ๊ฐ ์์ฑํ _ ๋ชจ๋ _ ์ฝ๋๊ฐ ์๋์ค๋ฌ์ด ๊ฒ์ ์๋๋๋ค ...)
406
406
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)"๋ ๋ฟ๋ง ์๋๋ผ ํ ๋น ์์ฒด๋ ๋ง์ฐฌ๊ฐ์ง์
๋๋ค .
409
409
410
410
``` ts
411
411
obj .prop || = foo ();
412
412
413
- // roughly equivalent to either of the following
413
+ // ๋ค์ ์ค ํ๋์ ๋๋ต ๋์ผํจ
414
414
415
415
obj .prop || (obj .prop = foo ());
416
416
@@ -419,14 +419,14 @@ if (!obj.prop) {
419
419
}
420
420
```
421
421
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 ) ์์๋ฅผ ํตํด _ ํญ์ _ ํ ๋น์ ์ํํ๋ ๊ฒ๊ณผ ์ด๋ป๊ฒ ๋ค๋ฅธ์ง ํ์ธํด๋ณด์ธ์ .
423
423
424
424
``` ts
425
425
const obj = {
426
426
get prop() {
427
427
console .log (" getter has run" );
428
428
429
- // Replace me !
429
+ // ์ด๊ณณ์ ๋ฐ๊ฟ๋ณด์ธ์ !
430
430
return Math .random () < 0.5 ;
431
431
},
432
432
set prop(_val : boolean ) {
@@ -446,10 +446,10 @@ console.log("This one *sometimes* runs the setter");
446
446
obj .prop || = foo ();
447
447
```
448
448
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 ) ๋์๊ฒ ํฐ ๊ฐ์ฌ๋ฅผ ํํฉ๋๋ค.
450
450
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/ ) .
453
453
454
454
## ` unknown ` on ` catch ` Clause Bindings
455
455
0 commit comments