From 4289bf1fbb823f410775b4c7d0533b7abd8e5f5f Mon Sep 17 00:00:00 2001 From: 3indblown Leaf <69508345+kraccoon-dev@users.noreply.github.com> Date: Tue, 1 Feb 2022 19:42:11 +0900 Subject: remove class 1 (#3922) --- .../ko/web/javascript/reference/classes/index.html | 36 ++++++------- .../classes/private_class_fields/index.html | 16 +++--- .../reference/functions/arrow_functions/index.html | 44 +++++++-------- .../functions/default_parameters/index.html | 26 ++++----- .../reference/global_objects/eval/index.html | 32 +++++------ .../reference/global_objects/globalthis/index.html | 4 +- .../reference/global_objects/infinity/index.html | 2 +- .../reference/global_objects/nan/index.html | 6 +-- .../number/negative_infinity/index.html | 2 +- .../global_objects/object/entries/index.html | 10 ++-- .../object/setprototypeof/index.html | 14 ++--- .../global_objects/regexp/exec/index.html | 10 ++-- .../reference/global_objects/regexp/index.html | 18 +++---- .../global_objects/regexp/regexp/index.html | 4 +- .../global_objects/regexp/test/index.html | 8 +-- .../global_objects/string/lastindexof/index.html | 8 +-- .../global_objects/string/slice/index.html | 12 ++--- .../reference/global_objects/undefined/index.html | 14 ++--- .../reference/lexical_grammar/index.html | 62 +++++++++++----------- .../reference/operators/await/index.html | 12 ++--- 20 files changed, 170 insertions(+), 170 deletions(-) (limited to 'files/ko/web/javascript/reference') diff --git a/files/ko/web/javascript/reference/classes/index.html b/files/ko/web/javascript/reference/classes/index.html index 8bb836788a..3e6bfc0a8f 100644 --- a/files/ko/web/javascript/reference/classes/index.html +++ b/files/ko/web/javascript/reference/classes/index.html @@ -15,7 +15,7 @@ translation_of: Web/JavaScript/Reference/Classes

Class를 정의하는 한 가지 방법은 class 선언을 이용하는 것입니다. class를 선언하기 위해서는 클래스의 이름(여기서 "Rectangle")과 함께 class 키워드를 사용해야 합니다.

-
class Rectangle {
+
class Rectangle {
   constructor(height, width) {
     this.height = height;
     this.width = width;
@@ -26,7 +26,7 @@ translation_of: Web/JavaScript/Reference/Classes
 
 

함수 선언과 클래스 선언의 중요한 차이점은 험수의 경우 정의하기 하기 전에 호출할 수 있지만, 클래스는 반드시 정의한 뒤에 사용할 수 있다는 점입니다. 다음 코드는 {{jsxref("ReferenceError")}}를 던질 것입니다.

-
const p = new Rectangle(); // ReferenceError
+
const p = new Rectangle(); // ReferenceError
 
 class Rectangle {}
 
@@ -37,7 +37,7 @@ class Rectangle {}

Class 표현식은 class를 정의하는 또 다른 방법입니다. Class 표현식은 이름을 가질 수도 있고, 갖지 않을 수도 있습니다. 이름을 가진 class 표현식의 이름은 클래스 body의 local scope에 한해 유효합니다. (하지만, 클래스의 (인스턴스 이름이 아닌) {{jsxref("Function.name", "name")}} 속성을 통해 찾을 수 있습니다).

-
// unnamed
+
// unnamed
 let Rectangle = class {
   constructor(height, width) {
     this.height = height;
@@ -80,7 +80,7 @@ console.log(Rectangle.name);
 
 

{{jsxref("Functions/Method_definitions", "메서드 정의", "", "true")}}도 참조해보세요.

-
class Rectangle {
+
class Rectangle {
   constructor(height, width) {
     this.height = height;
     this.width = width;
@@ -103,7 +103,7 @@ console.log(square.area); // 100

{{jsxref("Classes/static", "static", "", "true")}} 키워드는 클래스를 위한 정적(static) 메서드를 정의합니다. 정적 메서드는 클래스의 인스턴스화(instantiating) 없이 호출되며, 클래스의 인스턴스에서는 호출할 수 없습니다. 정적 메서드는 어플리케이션(application)을 위한 유틸리티(utility) 함수를 생성하는 데 주로 사용됩니다. 반면, 정적 속성은 캐시, 고정 환경설정 또는 인스턴스 간에 복제할 필요가 없는 기타 데이터에 유용합니다.

-
class Point {
+
class Point {
   constructor(x, y) {
     this.x = x;
     this.y = y;
@@ -132,7 +132,7 @@ console.log(Point.distance(p1, p2)); // 7.0710678118654755

메서드를 변수에 할당 한 다음 호출하는 것과 같이, 정적 메서드나 프로토타입 메서드가 {{jsxref("Operators/this", "this")}} 값 없이 호출될 때, this 값은 메서드 안에서 undefined가 됩니다. 이 동작은 {{jsxref("Strict_mode", "\"use strict\"")}} 명령어 없이도 같은 방식으로 동작하는데, class 문법 안에 있는 코드는 항상 strict mode 로 실행되기 때문입니다.

-
class Animal {
+
class Animal {
   speak() {
     return this;
   }
@@ -152,7 +152,7 @@ eat(); // undefined

위에 작성된 코드를 전통적 방식의 함수기반의 non–strict mode 구문으로 재작성하면, this 메서드 호출은 기본적으로 {{Glossary("Global_object", "전역 객체")}}인 초기 this 값에 자동으로 바인딩 됩니다. Strict mode에서는 자동 바인딩이 발생하지 않습니다; this 값은 전달된 대로 유지됩니다.

-
function Animal() { }
+
function Animal() { }
 
 Animal.prototype.speak = function() {
   return this;
@@ -173,7 +173,7 @@ eat(); // global object (in non-strict mode)

인스턴스 속성은 반드시 클래스 메서드 내에 정의되어야 합니다:

-
class Rectangle {
+
class Rectangle {
   constructor(height, width) {
     this.height = height;
     this.width = width;
@@ -182,7 +182,7 @@ eat(); // global object (in non-strict mode)

정적 (클래스사이드) 속성과 프로토타입 데이터 속성은 반드시 클래스 선언부 바깥쪽에서 정의되어야 합니다. 

-
Rectangle.staticWidth = 20;
+
Rectangle.staticWidth = 20;
 Rectangle.prototype.prototypeWidth = 25;
 
@@ -196,7 +196,7 @@ Rectangle.prototype.prototypeWidth = 25;

자바스크립트의 필드 선언 문법을 사용해서 위의 예제는 아래와 같이 다시 쓰여질 수 있습니다.

-
class Rectangle {
+
class Rectangle {
   height = 0;
   width;
   constructor(height, width) {
@@ -215,7 +215,7 @@ Rectangle.prototype.prototypeWidth = 25;
 
 

private 필드를 사용하면 아래와 같이 예제를 개선할 수 있습니다.

-
class Rectangle {
+
class Rectangle {
   #height = 0;
   #width;
   constructor(height, width) {
@@ -238,7 +238,7 @@ Rectangle.prototype.prototypeWidth = 25;
 
 

{{jsxref("Classes/extends", "extends")}} 키워드는 클래스 선언이나 클래스 표현식에서 다른 클래스의 자식 클래스를 생성하기 위해 사용됩니다.

-
class Animal {
+
class Animal {
   constructor(name) {
     this.name = name;
   }
@@ -265,7 +265,7 @@ d.speak(); // Mitzie barks.

또한 es5에서 사용되던 전통적인 함수 기반의 클래스를 통하여 확장할 수도 있습니다.

-
function Animal (name) {
+
function Animal (name) {
   this.name = name;
 }
 
@@ -286,7 +286,7 @@ d.speak(); // Mitzie barks.
 
 

클래스는 생성자가 없는 객체(non-constructible)을 확장할 수 없습니다. 만약 기존의 생성자가 없는 객체을 확장하고 싶다면, 이 메서드를 사용하세요. {{jsxref("Object.setPrototypeOf()")}}:

-
const Animal = {
+
const Animal = {
   speak() {
     console.log(`${this.name} makes a noise.`);
   }
@@ -310,7 +310,7 @@ d.speak(); // Mitzie makes a noise.

예를 들어, {{jsxref("Array.map", "map()")}}과 같은 기본 생성자를 반환하는 메서드를 사용할 때 이 메서드가 MyArray 객체 대신 Array 객체가 반환하도록 하고 싶을 것입니다. {{jsxref("Symbol.species")}} 심볼은 이러한 것을 가능하게 해줍니다:

-
class MyArray extends Array {
+
class MyArray extends Array {
   // 부모 Array 생성자로 species 덮어쓰기
   static get [Symbol.species]() { return Array; }
 }
@@ -324,7 +324,7 @@ console.log(mapped instanceof Array);   // true

{{jsxref("Operators/super", "super")}} 키워드는 객체의 부모가 가지고 있는 메서드를 호출하기 위해 사용됩니다. 이는 프로토타입 기반 상속보다 좋은 점 중 하나입니다.

-
class Cat {
+
class Cat {
   constructor(name) {
     this.name = name;
   }
@@ -352,7 +352,7 @@ l.speak();
 
 

슈퍼클래스를 인자로 받고 이 슈퍼클래스를 확장하는 서브클래스를 생성하여 반환하는 함수를 사용하여 ECMAScript에서 믹스-인을 구현할 수 있습니다:

-
var calculatorMixin = Base => class extends Base {
+
var calculatorMixin = Base => class extends Base {
   calc() { }
 };
 
@@ -362,7 +362,7 @@ var randomizerMixin = Base => class extends Base {
 
 

위 믹스-인을 사용하는 클래스는 다음과 같이 작성할 수 있습니다:

-
class Foo { }
+
class Foo { }
 class Bar extends calculatorMixin(randomizerMixin(Foo)) { }

클래스 재정의

diff --git a/files/ko/web/javascript/reference/classes/private_class_fields/index.html b/files/ko/web/javascript/reference/classes/private_class_fields/index.html index ea5508ab27..0e31821cb3 100644 --- a/files/ko/web/javascript/reference/classes/private_class_fields/index.html +++ b/files/ko/web/javascript/reference/classes/private_class_fields/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Classes/Private_class_fields

Syntax

-
class ClassWithPrivateField {
+
class ClassWithPrivateField {
   #privateField
 }
 
@@ -35,7 +35,7 @@ class ClassWithPrivateStaticField {
 
 

static 메소드에서만 static 변수들을 호출할 수 있다는 제약은 그대로 유지된다.

-
class ClassWithPrivateStaticField {
+
class ClassWithPrivateStaticField {
   static #PRIVATE_STATIC_FIELD
 
   static publicStaticMethod() {
@@ -52,7 +52,7 @@ console.assert(ClassWithPrivateStaticField.publicStaticMethod() === 42)

이는 this 를 사용함에 있어 예상치 못한 동작을 야기할 수 있다.

-
class BaseClassWithPrivateStaticField {
+
class BaseClassWithPrivateStaticField {
   static #PRIVATE_STATIC_FIELD
 
   static basePublicStaticMethod() {
@@ -77,7 +77,7 @@ console.assert(error instanceof TypeError)

캡슐화(encapsulation) 는 언어로부터 강제된다(enforced by the language). 즉, scope 밖에서 # 이름에 접근하는 것은 syntax error 이다.

-
class ClassWithPrivateField {
+
class ClassWithPrivateField {
   #privateField
 
   constructor() {
@@ -97,7 +97,7 @@ instance.#privateField === 42 // Syntax error

private static 메소드는 generator, async 그리고 async generator 함수가 될 수 있다.

-
class ClassWithPrivateStaticMethod {
+
class ClassWithPrivateStaticMethod {
   static #privateStaticMethod() {
     return 42
   }
@@ -116,7 +116,7 @@ console.assert(ClassWithPrivateStaticMethod.publicStaticMethod2() === 42);

이는 this 를 사용할 때 예상치 못한 동작을 발생시킬 수 있다. (이는 this binding rule 이 적용되기 때문이다.) 다음 예시에서 Derived.publicStaticMethod2() 를 호출할 때, this 는 class Derived (Base 가 아니라) 를 가리킨다. 

-
class Base {
+
class Base {
   static #privateStaticMethod() {
     return 42;
   }
@@ -137,7 +137,7 @@ console.log(Derived.publicStaticMethod2()); // TypeError

private 인스턴스 메소드는 private 인스턴스 필드와는 다르게 class 인스턴스로부터 접근 가능하다.

-
class ClassWithPrivateMethod {
+
class ClassWithPrivateMethod {
   #privateMethod() {
     return 'hello world'
   }
@@ -153,7 +153,7 @@ console.log(instance.getPrivateMessage())
 
 

private 인스턴스 메소드는 generator, async 그리고 async generator 함수가 될 수 있다. private getter 와 setter 또한 가능하다:

-
class ClassWithPrivateAccessor {
+
class ClassWithPrivateAccessor {
   #message
 
   get #decoratedMessage() {
diff --git a/files/ko/web/javascript/reference/functions/arrow_functions/index.html b/files/ko/web/javascript/reference/functions/arrow_functions/index.html
index cff8d043ae..2a12888f65 100644
--- a/files/ko/web/javascript/reference/functions/arrow_functions/index.html
+++ b/files/ko/web/javascript/reference/functions/arrow_functions/index.html
@@ -27,7 +27,7 @@ original_slug: Web/JavaScript/Reference/Functions/애로우_펑션
 
 

기본 구문

-
(param1, param2, …, paramN) => { statements }
+
(param1, param2, …, paramN) => { statements }
 (param1, param2, …, paramN) => expression
 // 다음과 동일함:  => { return expression; }
 
@@ -40,7 +40,7 @@ original_slug: Web/JavaScript/Reference/Functions/애로우_펑션
 
 

고급 구문

-
// 객체 리터럴 표현을 반환하기 위해서는 함수 본문(body)을 괄호 속에 넣음:
+
// 객체 리터럴 표현을 반환하기 위해서는 함수 본문(body)을 괄호 속에 넣음:
 params => ({foo: bar})
 
 // 나머지 매개변수기본 매개변수를 지원함
@@ -64,7 +64,7 @@ f();  // 6
 
 

일부 함수 패턴에서는, 짧은 함수가 환영받습니다. 비교해 보세요:

-
var elements = [
+
var elements = [
   'Hydrogen',
   'Helium',
   'Lithium',
@@ -114,7 +114,7 @@ elements.이는 객체 지향 스타일로 프로그래밍할 때 별로 좋지않습니다.

-
function Person() {
+
function Person() {
   // Person() 생성자는 `this`를 자신의 인스턴스로 정의.
   this.age = 0;
 
@@ -130,7 +130,7 @@ var p = new Person();

ECMAScript 3/5 에서는, 이 문제를 this 값을 폐쇄될 수 있는 (비전역) 변수에 할당하여 해결했습니다.

-
function Person() {
+
function Person() {
   var that = this;
   that.age = 0;
 
@@ -146,7 +146,7 @@ var p = new Person();

따라서 다음 코드에서 setInterval에 전달 된 함수 내부의 thissetInterval을 포함한 function의 this와 동일한 값을 갖습니다.

-
function Person(){
+
function Person(){
   this.age = 0;
 
   setInterval(() => {
@@ -160,7 +160,7 @@ var p = new Person();

this가 렉시컬(lexical, 정적)임을 감안하면, this에 관한 엄격 모드 규칙은 그냥 무시됩니다.

-
var f = () => { 'use strict'; return this; };
+
var f = () => { 'use strict'; return this; };
 f() === window; // 혹은 전역객체

엄격 모드의 나머지 규칙은 평소대로 적용합니다.

@@ -173,7 +173,7 @@ f() === window; // 혹은 전역객체

This code sample using Chrome 81 demonstrates that arrow functions allow the creation of global variables in such situations (both for a concise body and for a normal function body):

-
> f1 = x => { y = x; console.log(`x: ${x}, y: ${y}`); return x + 1; }
+
> f1 = x => { y = x; console.log(`x: ${x}, y: ${y}`); return x + 1; }
 x => { y = x; console.log(`x: ${x}, y: ${y}`); return x + 1; }
 
 > y
@@ -230,7 +230,7 @@ VM51891:1 Uncaught ReferenceError: z1 is not defined
 
 

화살표 함수에서는 this가 바인딩되지 않았기 때문에, call() 또는 apply() 메서드는  인자만 전달 할 수 있습니다. this는 무시됩니다.

-
var adder = {
+
var adder = {
   base : 1,
 
   add : function(a) {
@@ -255,7 +255,7 @@ console.log(adder.addThruCall(1)); // 이도 2가 콘솔에 출력될 것임화살표 함수는 arguments 객체를 바인드 하지 않습니다.  때문에, arguments는  그저 둘러싸는 범위(scope) 내 이름에 대한 참조입니다.

-
var arguments = [1, 2, 3];
+
var arguments = [1, 2, 3];
 var arr = () => arguments[0];
 
 arr(); // 1
@@ -269,7 +269,7 @@ foo(1); // 2

화살표 함수는 자신의 arguments 객체가 없지만, 대부분의 경우에 나머지 매개변수가 좋은 대안입니다:

-
function foo(n) {
+
function foo(n) {
   var f = (...args) => args[0] + n;
   return f(2);
 }
@@ -280,7 +280,7 @@ foo(1); // 3

이야기 했듯이, 화살표 함수 표현은 메소드 함수가 아닌 형태로 사용 할 수 있습니다. 메소드로 사용하려고 한면 무슨일이 발생하는지 봅시다.

-
'use strict';
+
'use strict';
 
 var obj = { // does not create a new scope
   i: 10,
@@ -295,7 +295,7 @@ obj.c(); // prints 10, Object {...}
 
 

화살표 함수는 자신의 this를 가지고("bind" 바인드)있지 않습니다.{{jsxref("Object.defineProperty()")}}

-
'use strict';
+
'use strict';
 
 var obj = {
   a: 10
@@ -312,14 +312,14 @@ Object.defineProperty(obj, 'b', {
 
 

화살표 함수는 생성자로서 사용될 수 없으며 new와 함께 사용하면 오류가 발생합니다.

-
var Foo = () => {};
+
var Foo = () => {};
 var foo = new Foo(); // TypeError: Foo is not a constructor

prototype 속성 사용

화살표 함수는 prototype 속성이 없습니다.

-
var Foo = () => {};
+
var Foo = () => {};
 console.log(Foo.prototype); // undefined

yield 키워드 사용

@@ -336,7 +336,7 @@ console.log(Foo.prototype); // undefined

block바디는 자동으로 값을 반환하지 않습니다. return을 사용해서 값을 반환해야 합니다.

-
var func = x => x * x;                  // concise 바디, 생략된 "return" 여기서는 x * x
+
var func = x => x * x;                  // concise 바디, 생략된 "return" 여기서는 x * x
 var func = (x, y) => { return x + y; }; // block 바디, "return"이 필요
 
@@ -344,7 +344,7 @@ var func = (x, y) => { return x + y; }; // block 바디, "return"이 필요

간결한 구문 params => {object:literal}을 사용한 객체 리터럴 반환은 예상대로 작동하지 않음을 명심하세요:

-
var func = () => {  foo: 1  };
+
var func = () => {  foo: 1  };
 // func() 호출은 undefined를 반환!
 
 var func = () => {  foo: function() {}  };
@@ -354,19 +354,19 @@ var func = () => {  foo: function() {}  };
 
 

객체 리터럴를 괄호로 감싸는 것을 기억하세요:

-
var func = () => ({ foo: 1 });
+
var func = () => ({ foo: 1 });

줄바꿈

화살표 함수는 파라메터와 화살표 사이에 개행 문자를 포함 할 수 없습니다.

-
var func = (a, b, c)
+
var func = (a, b, c)
            => 1;
 // SyntaxError: expected expression, got '=>'

하지만, 보기 좋은 코드를 유지하고 싶다면, 아래에 보는 것처럼 괄호나 개행을 둠으로써 이를 수정할 수 있습니다.

-
var func = (a, b, c) =>
+
var func = (a, b, c) =>
   1;
 
 var func = (a, b, c) => (
@@ -389,7 +389,7 @@ var func = (a, b, c) => {
 
 

화살표 함수 내의 화살표는 연산자가 아닙니다. 그러나 화살표 함수는 평범한 함수와 비교했을 때 operator precedence와 다르게 반응하는 특별한 파싱룰을 가지고 있습니다.

-
let callback;
+
let callback;
 
 callback = callback || function() {}; // ok
 
@@ -403,7 +403,7 @@ callback = callback || (() => {});    // ok
 
 

기본 사용법

-
//  empty 화살표 함수는 undefined를 반환 
+
//  empty 화살표 함수는 undefined를 반환 
 let empty = () => {};
 
 (() => 'foobar')();
diff --git a/files/ko/web/javascript/reference/functions/default_parameters/index.html b/files/ko/web/javascript/reference/functions/default_parameters/index.html
index 15828a0c51..d047ebaaa4 100644
--- a/files/ko/web/javascript/reference/functions/default_parameters/index.html
+++ b/files/ko/web/javascript/reference/functions/default_parameters/index.html
@@ -17,7 +17,7 @@ translation_of: Web/JavaScript/Reference/Functions/Default_parameters
 
 

구문

-
+
 function fnName(param1 = defaultValue1, ..., paramN = defaultValueN) { ... }
 
@@ -29,7 +29,7 @@ function fnName(param1 = defaultValue1, ..., paramN = defaultValueN) { ... }

다음 예제에서, multiply호출시 b에 할당된  값이 없다면, b 값은 a*b를 평가할 때 undefined일 거고 multiply 호출은 NaN이 반환됩니다. 

-
function multiply(a, b) {
+
function multiply(a, b) {
   return a * b
 }
 
@@ -39,7 +39,7 @@ multiply(5)     // NaN !
 
 

이를 방지하기 위해서, 아래 두번째 줄과 같이  multiply 함수가 오직 한 개의 인수만 있다면  b를  1로 설정하는 방식을 사용하곤 했습니다.

-
function multiply(a, b) {
+
function multiply(a, b) {
   b = (typeof b !== 'undefined') ?  b : 1
   return a*b
 }
@@ -50,7 +50,7 @@ multiply(5)      // 5
 
 

ES2015의 기본값 매개변수로 함수 내부 에서의 검사는 더 이상 필요치 않습니다. 이제, 간단히 함수 머리(head)에서 b의 기본값으로 1 로 설정할 수 있습니다:

-
function multiply(a, b = 1) {
+
function multiply(a, b = 1) {
   return a*b
 }
 
@@ -65,7 +65,7 @@ multiply(5, undefined)  // 5
 
 

아래 예제중 두 번째 호출에서, 설사 두 번째 인수를 호출할 때 명시해서 undefined (null 혹은 {{glossary("falsy")}} 값이 아니긴 하지만 )로 설정하더라도 , num 인수의 값은 여전히 기본값입니다.

-
function test(num = 1) {
+
function test(num = 1) {
   console.log(typeof num)
 }
 
@@ -81,7 +81,7 @@ test(null)        // 'object' (num 은 null로 설정됨)
 
 

기본 인수는 호출 시 에 평가됩니다, 그래서 Python의 경우 와는 달리, 함수가 호출될 때마다 새로운 객체가 생성됩니다.

-
function append(value, array = []) {
+
function append(value, array = []) {
   array.push(value)
   return array
 }
@@ -93,7 +93,7 @@ append(2)  // [2], [1, 2]가 아니라
 
 

이는 심지어 함수 및 변수에도 적용됩니다:

-
function callSomething(thing = something()) {
+
function callSomething(thing = something()) {
   return thing
 }
 
@@ -111,7 +111,7 @@ callSomething()  // 2
 
 

매개 변수가 여러개일 때 앞쪽에( 왼쪽 부분) 정의된 매개변수는 뒷쪽에 정의된 매개변수의 기본값에  바로 사용할 수 있습니다.

-
function greet(name, greeting, message = greeting + ' ' + name) {
+
function greet(name, greeting, message = greeting + ' ' + name) {
   return [name, greeting, message]
 }
 
@@ -121,7 +121,7 @@ greet('David', 'Hi', 'Happy Birthday!')   // ["David", "Hi", "Happy Birthday!"]
 
 

이 기능은,  얼마나 많은 경계 조건(edge case)를 다룰수 있는지 보여주는, 아래 예제로 거의 설명 가능합니다.

-
function go() {
+
function go() {
   return ':P'
 }
 
@@ -172,13 +172,13 @@ withoutDefaults.call({value:"=^_^="});
 
 

아래 함수는 호출되면 ReferenceError 를 발생시킵니다. 매개변수 기본값이 함수 내부의 자식 유효범위를 참조할 수 없기 때문입니다.

-
function f(a = go()) { // `f`가 호출 되면 `ReferenceError` 발생
+
function f(a = go()) { // `f`가 호출 되면 `ReferenceError` 발생
   function go() { return ':P' }
 }

...그리고 아래 함수는 undefined 를 프린트 하는데,  var a 가 함수 내부 대상의 유효범위내에서만 효과를 가지기 때문입니다. ( 매개변수 목록이 대상인 부모 스코프가 아니라)

-
function f(a, b = () => console.log(a)) {
+
function f(a, b = () => console.log(a)) {
   var a = 1
   b() // `undefined`를 인쇄하는데, 매개변수 기본값이 자체 스코프에 있기 때문입니다
 } 
@@ -187,7 +187,7 @@ withoutDefaults.call({value:"=^_^="});

매개변수는 여전히 왼쪽에서 오른쪽으로 설정됩니다. 아래 예제에서 뒷쪽에 기본값이 없는 매개변수가 있지만 기본값 매개변수를 덮어씁니다.

-
function f(x=1, y) {
+
function f(x=1, y) {
   return [x, y];
 }
 
@@ -199,7 +199,7 @@ f(2)  // [2, undefined]
 
 

기본값 할당을 {{jsxref("Operators/Destructuring_assignment", "destructuring assignment", "", 1)}} 표기와 함께 사용할 수 있습니다:

-
function f([x, y] = [1, 2], {z: z} = {z: 3}) {
+
function f([x, y] = [1, 2], {z: z} = {z: 3}) {
   return x + y + z
 }
 
diff --git a/files/ko/web/javascript/reference/global_objects/eval/index.html b/files/ko/web/javascript/reference/global_objects/eval/index.html
index d599cadbe9..d7bcfeb182 100644
--- a/files/ko/web/javascript/reference/global_objects/eval/index.html
+++ b/files/ko/web/javascript/reference/global_objects/eval/index.html
@@ -72,7 +72,7 @@ eval(expression.toString());            // 4를 반환
 
 

eval을 사용하는 나쁜 코드:

-
function looseJsonParse(obj){
+
function looseJsonParse(obj){
     return eval(obj);
 }
 console.log(looseJsonParse(
@@ -82,7 +82,7 @@ console.log(looseJsonParse(
 
 

eval이 없는 코드:

-
function looseJsonParse(obj){
+
function looseJsonParse(obj){
     return Function('"use strict";return (' + obj + ')')();
 }
 console.log(looseJsonParse(
@@ -92,7 +92,7 @@ console.log(looseJsonParse(
 
 

위의 두 코드는 얼핏 보면 같은 방식으로 실행되는 것처럼 보이지만, eval이 있는 코드가 훨씬 느립니다. 평가되는 객체의 c: new Date()를 주목하세요. eval이 없는 함수의 경우 이 객체는 전역 범위에서 평가되기 때문에 브라우저에서는 Date를 같은 이름의 지역 변수가 아니라 window.Date로 취급할 수 있습니다. 그러나 eval()을 사용하는 코드에서는 아래와 같은 경우도 존재할 수 있기 때문에 Date를 이렇게 취급할 수 없습니다.

-
function Date(n){
+
function Date(n){
     return ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"][n%7 || 0];
 }
 function looseJsonParse(obj){
@@ -107,7 +107,7 @@ console.log(looseJsonParse(
 
 

만약 위의 상황에서 실제로 새로 선언한 Date 함수를 Function()에서 실행해야 하는 상황을 생각해 봅시다. 이렇게 되면 eval()로 돌아가야 할까요? 물론 아닙니다. 아래의 접근을 시도해 보세요.

-
function Date(n){
+
function Date(n){
     return ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"][n%7 || 0];
 }
 function runCodeWithDateFunction(obj){
@@ -132,7 +132,7 @@ console.log(runCodeWithDateFunction(
 
 

마지막으로 코드 최소화의 측면에서 살펴보면, 위와 같이 Function()을 사용했을 때는 아래의 최소화된 코드와 같이 함수의 인자 이름 역시 짧게 줄일 수 있으므로 runCodeWithDateFunction에 전달하는 코드 문자열을 더욱 효율적으로 줄일 수 있습니다.

-
console.log(Function('"use strict";return(function(a){return a(5)})')()(function(a){
+
console.log(Function('"use strict";return(function(a){return a(5)})')()(function(a){
 return"Monday Tuesday Wednesday Thursday Friday Saturday Sunday".split(" ")[a%7||0]}));

자주 쓰이는 용례에 대해서는 eval()이나 Function()보다 안전하고 빠른 대안도 존재합니다.

@@ -141,7 +141,7 @@ return"Monday Tuesday Wednesday Thursday Friday Saturday Sunday".split(" ")[a%7|

속성명으로 속성을 찾는 데 eval()을 사용해서는 안 됩니다. 다음 예제와 같이 코드를 실행하기 전까지는 접근할 속성을 알 수 없는 상황을 생각해 봅시다. 이 상황은 eval로 처리할 수 있습니다.

-
var obj = { a: 20, b: 30 };
+
var obj = { a: 20, b: 30 };
 var propname = getPropName();  // "a" 또는 "b"를 반환
 
 eval( "var result = obj." + propname );
@@ -149,21 +149,21 @@ eval( "var result = obj." + propname );
 
 

그러나 여기에서 eval()을 쓸 필요가 없고, 지양되어야 합니다. 그 대신 훨씬 빠르고 안전한 속성 접근자를 사용하여야 합니다.

-
var obj = { a: 20, b: 30 };
+
var obj = { a: 20, b: 30 };
 var propname = getPropName();  // "a" 또는 "b"를 반환
 var result = obj[ propname ];  //  obj[ "a" ]는 obj.a와 동일함
 

이 방법으로 더 깊은 속성에도 접근할 수 있습니다. eval()을 사용한다면 다음과 같을 것입니다.

-
var obj = {a: {b: {c: 0}}};
+
var obj = {a: {b: {c: 0}}};
 var propPath = getPropPath();  // "a.b.c"를 반환한다고 가정
 
 eval( 'var result = obj.' + propPath );

여기서 eval()의 사용을 피하려면 속성 경로를 split한 다음 순서대로 접근할 수도 있습니다.

-
function getDescendantProp(obj, desc) {
+
function getDescendantProp(obj, desc) {
   var arr = desc.split('.');
   while (arr.length) {
     obj = obj[arr.shift()];
@@ -177,7 +177,7 @@ var result = getDescendantProp(obj, propPath);

속성에 값을 대입하는 것도 비슷하게 할 수 있습니다.

-
function setDescendantProp(obj, desc, value) {
+
function setDescendantProp(obj, desc, value) {
   var arr = desc.split('.');
   while (arr.length > 1) {
     obj = obj[arr.shift()];
@@ -194,7 +194,7 @@ var result = setDescendantProp(obj, propPath, 1);  // test.a.b.c의 값은 1로
 
 

JavaScript의 함수는 1급 객체이므로 다른 API에 함수를 인자로 전달할 수도 있고, 변수나 객체의 속성으로 대입할 수도 있습니다. 다수의 DOM API는 이 점을 염두에 두고 설계되므로, 다음과 같이 코드를 짜야 합니다.

-
// setTimeout(" ... ", 1000) 대신에
+
// setTimeout(" ... ", 1000) 대신에
 setTimeout(function() { ... }, 1000);
 
 // elt.setAttribute("onclick", "...") 대신에
@@ -222,7 +222,7 @@ elt.addEventListener("click", function() { ... } , false); 

아래 코드에서 eval()를 포함하는 문장은 모두 42를 반환합니다. 전자는 문자열 "x + y + 1"을, 후자는 문자열 "42"를 평가합니다.

-
var x = 2;
+
var x = 2;
 var y = 39;
 var z = "42";
 eval("x + y + 1"); // 42를 반환
@@ -233,14 +233,14 @@ eval(z);           // 42를 반환
 
 

다음 예제에서는 eval()을 사용하여 str 문자열을 평가합니다. 이 문자열은 x가 5이면 로그를 출력한 다음 z에 42를 할당하고, 그렇지 않으면 z에 0 을 할당하는 JavaScript 코드입니다. 두 번째 문장이 실행되면, eval()은 이 문장의 집합을 수행하고, z에 할당된 값을 반환합니다.

-
var x = 5;
+
var x = 5;
 var str = "if (x == 5) {console.log('z is 42'); z = 42;} else z = 0; ";
 
 console.log("z is ", eval(str));

여러 값을 정의할 경우 마지막 값을 반환합니다.

-
var x = 5;
+
var x = 5;
 var str = "if (x == 5) {console.log('z is 42'); z = 42; x = 420; } else z = 0;";
 
 console.log('x is ', eval(str)); // z는 42, x는 420
@@ -249,7 +249,7 @@ console.log('x is ', eval(str)); // z는 42, x는 420

eval() 은 마지막 표현식의 평가값을 반환합니다.

-
var str = "if ( a ) { 1+1; } else { 1+2; }";
+
var str = "if ( a ) { 1+1; } else { 1+2; }";
 var a = true;
 var b = eval(str);  // 2를 반환
 
@@ -262,7 +262,7 @@ console.log("b is : " + b);

함수 정의 문자열로서의 eval 은 앞뒤를 "("와 ")"로 감싸야 한다

-
var fctStr1 = "function a() {}"
+
var fctStr1 = "function a() {}"
 var fctStr2 = "(function a() {})"
 var fct1 = eval(fctStr1)  // undefined를 반환
 var fct2 = eval(fctStr2)  // 함수를 반환
diff --git a/files/ko/web/javascript/reference/global_objects/globalthis/index.html b/files/ko/web/javascript/reference/global_objects/globalthis/index.html
index a06d8520dc..8a46c92c54 100644
--- a/files/ko/web/javascript/reference/global_objects/globalthis/index.html
+++ b/files/ko/web/javascript/reference/global_objects/globalthis/index.html
@@ -37,7 +37,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/globalThis
 
 

globalThis 없이 현재 환경의 전역 객체를 가져오는 방법 중 유일하게 믿을만한 방법은 Function('return this')() 입니다. 그러나 일부 환경에서는 CSP 위반에 걸리는 코드이므로, es6-shim은 대신 다음 검사를 수행합니다.

-
var getGlobal = function () {
+
var getGlobal = function () {
   if (typeof self !== 'undefined') { return self; }
   if (typeof window !== 'undefined') { return window; }
   if (typeof global !== 'undefined') { return global; }
@@ -53,7 +53,7 @@ if (typeof globals.setTimeout !== 'function') {
 
 

globalThis를 사용할 수 있으면 환경별 전역 객체 검사는 더 이상 필요하지 않습니다.

-
if (typeof globalThis.setTimeout !== 'function') {
+
if (typeof globalThis.setTimeout !== 'function') {
   // no setTimeout in this environment!
 }
diff --git a/files/ko/web/javascript/reference/global_objects/infinity/index.html b/files/ko/web/javascript/reference/global_objects/infinity/index.html index ffda333c14..8c5a8c6e77 100644 --- a/files/ko/web/javascript/reference/global_objects/infinity/index.html +++ b/files/ko/web/javascript/reference/global_objects/infinity/index.html @@ -27,7 +27,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Infinity

예제

-
console.log(Infinity);          /* Infinity */
+
console.log(Infinity);          /* Infinity */
 console.log(Infinity + 1);      /* Infinity */
 console.log(Math.pow(10,1000)); /* Infinity */
 console.log(Math.log(0));       /* -Infinity */
diff --git a/files/ko/web/javascript/reference/global_objects/nan/index.html b/files/ko/web/javascript/reference/global_objects/nan/index.html
index e2e4aa9bac..0ddec1ad2d 100644
--- a/files/ko/web/javascript/reference/global_objects/nan/index.html
+++ b/files/ko/web/javascript/reference/global_objects/nan/index.html
@@ -39,7 +39,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/NaN
 
 

NaN은 다른 모든 값과 비교(==, !=, ===, !==)했을 때 같지 않으며, 다른 NaN과도 같지 않습니다. NaN의 판별은 {{jsxref("Number.isNaN()")}} 또는 {{jsxref("Global_Objects/isNaN", "isNaN()")}}을 사용하면 제일 분명하게 수행할 수 있습니다. 아니면, 오로지 NaN만이 자기자신과 비교했을 때 같지 않음을 이용할 수도 있습니다.

-
NaN === NaN;        // false
+
NaN === NaN;        // false
 Number.NaN === NaN; // false
 isNaN(NaN);         // true
 isNaN(Number.NaN);  // true
@@ -52,13 +52,13 @@ valueIsNaN(Number.NaN); // true
 
 

그러나 isNaN()Number.isNaN()의 차이를 주의해야 합니다. isNaN은 현재 값이 NaN이거나, 숫자로 변환했을 때 NaN이 되면 참을 반환하지만, Number.isNaN은 현재 값이 NaN이어야만 참을 반환합니다.

-
isNaN('hello world'); // true
+
isNaN('hello world'); // true
 Number.isNaN('hello world'); // false
 

덧붙여서, 일부 배열 메서드는 NaN을 찾을 수 없습니다.

-
let arr = [2, 4, NaN, 12];
+
let arr = [2, 4, NaN, 12];
 arr.indexOf(NaN);                      // -1 (false)
 arr.includes(NaN);                     // true
 arr.findIndex(n => Number.isNaN(n));   // 2
diff --git a/files/ko/web/javascript/reference/global_objects/number/negative_infinity/index.html b/files/ko/web/javascript/reference/global_objects/number/negative_infinity/index.html index d6567e687e..43ae38f357 100644 --- a/files/ko/web/javascript/reference/global_objects/number/negative_infinity/index.html +++ b/files/ko/web/javascript/reference/global_objects/number/negative_infinity/index.html @@ -46,7 +46,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY

다음 코드에서 smallNumber는 JavaScript의 최솟값보다 작은 값을 할당받습니다. {{jsxref("Statements/if...else", "if")}} 문이 실행되면, smallNumber의 값이 -Infinity이므로 smallNumber는 계산에 좀 더 적합한 값을 다시 할당합니다.

-
var smallNumber = (-Number.MAX_VALUE) * 2;
+
var smallNumber = (-Number.MAX_VALUE) * 2;
 
 if (smallNumber === Number.NEGATIVE_INFINITY) {
   smallNumber = returnFinite();
diff --git a/files/ko/web/javascript/reference/global_objects/object/entries/index.html b/files/ko/web/javascript/reference/global_objects/object/entries/index.html
index 3056d99d31..082e931936 100644
--- a/files/ko/web/javascript/reference/global_objects/object/entries/index.html
+++ b/files/ko/web/javascript/reference/global_objects/object/entries/index.html
@@ -15,7 +15,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/entries
 
 

Syntax

-
Object.entries(obj)
+
Object.entries(obj)

Parameters

@@ -36,7 +36,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/entries

기본적으로 지원하지 않는 이전 환경에서 호환 가능한 Object.entries 지원을 추가하려면 tc39/proposal-object-values-entries에 Object.entries의 데모 구현을 찾을 수 있습니다 (IE에 대한 지원이 필요하지 않은 경우) , es-shims/Object.entries 저장소에있는 polyfill을 사용하거나 아래에 나열된 polyfill을 간단하게 배치 할 수 있습니다.

-
if (!Object.entries)
+
if (!Object.entries)
   Object.entries = function( obj ){
     var ownProps = Object.keys( obj ),
         i = ownProps.length,
@@ -54,7 +54,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/entries
 
 

Examples

-
const obj = { foo: 'bar', baz: 42 };
+
const obj = { foo: 'bar', baz: 42 };
 console.log(Object.entries(obj)); // [ ['foo', 'bar'], ['baz', 42] ]
 
 // array like object
@@ -94,7 +94,7 @@ console.log(`${key} ${value}`); // "a 5", "b 7", "c 9"
 
 
 
-
const obj = { foo: 'bar', baz: 42 };
+
const obj = { foo: 'bar', baz: 42 };
 const map = new Map(Object.entries(obj));
 console.log(map); // Map { foo: "bar", baz: 42 }
 
@@ -103,7 +103,7 @@ console.log(map); // Map { foo: "bar", baz: 42 }

Array Destructuring을 사용하면 객체를 쉽게 반복 할 수 있습니다.

-
const obj = { foo: 'bar', baz: 42 };
+
const obj = { foo: 'bar', baz: 42 };
 Object.entries(obj).forEach(([key, value]) => console.log(`${key}: ${value}`)); // "foo: bar", "baz: 42"
 
diff --git a/files/ko/web/javascript/reference/global_objects/object/setprototypeof/index.html b/files/ko/web/javascript/reference/global_objects/object/setprototypeof/index.html index 64f7a89a18..4b01abdf50 100644 --- a/files/ko/web/javascript/reference/global_objects/object/setprototypeof/index.html +++ b/files/ko/web/javascript/reference/global_objects/object/setprototypeof/index.html @@ -14,7 +14,7 @@ browser-compat: javascript.builtins.Object.setPrototypeOf

Syntax

-
Object.setPrototypeOf(obj, prototype);
+
Object.setPrototypeOf(obj, prototype);

Parameters

@@ -37,14 +37,14 @@ browser-compat: javascript.builtins.Object.setPrototypeOf

Examples

-
var dict = Object.setPrototypeOf({}, null);
+
var dict = Object.setPrototypeOf({}, null);
 

Polyfill

예전 버전의 프로퍼티 {{jsxref("Object.prototype.__proto__")}} 를 사용한다면, 우리는 쉽게 Object.setPrototypeOf 가 쉽게 정의 할수 있다.

-
// Only works in Chrome and FireFox, does not work in IE:
+
// Only works in Chrome and FireFox, does not work in IE:
 Object.setPrototypeOf = Object.setPrototypeOf || function(obj, proto) {
   obj.__proto__ = proto;
   return obj;
@@ -55,7 +55,7 @@ Object.setPrototypeOf = Object.setPrototypeOf || function(obj, proto) {
 
 

Object.getPrototypeOf() and {{jsxref("Object.proto", "Object.prototype.__proto__")}} 의 결합은 새로운 프로토타입 오브젝트에 전반적인 프로토타입 Chain을 설정하도록 할수 있다.

-
/**
+
/**
 *** Object.appendChain(@object, @prototype)
 *
 * Appends the first non-native prototype of a chain to a new prototype.
@@ -103,7 +103,7 @@ Object.appendChain = function(oChain, oProto) {
 
 

First example: 프로토타입에 Chain 설정하기

-
function Mammal() {
+
function Mammal() {
   this.isMammal = 'yes';
 }
 
@@ -129,7 +129,7 @@ console.log(oCat.breathing); // 'yes'
 
 

Second example: 객체 Constructor의 인스턴스에 존재하는 원래 값을 변경 및 해당 객체 프로토타입에 Chain 설정하기

-
function MySymbol() {
+
function MySymbol() {
   this.isSymbol = 'yes';
 }
 
@@ -146,7 +146,7 @@ console.log(typeof oPrime); // 'object'
 
 

Third example: Function.prototype객체에 Chain을 설정하고 그 Chain에 새로운 함수를 설정하기

-
function Person(sName) {
+
function Person(sName) {
   this.identity = sName;
 }
 
diff --git a/files/ko/web/javascript/reference/global_objects/regexp/exec/index.html b/files/ko/web/javascript/reference/global_objects/regexp/exec/index.html
index d20573f473..eb02391603 100644
--- a/files/ko/web/javascript/reference/global_objects/regexp/exec/index.html
+++ b/files/ko/web/javascript/reference/global_objects/regexp/exec/index.html
@@ -26,7 +26,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/exec
 
 

구문

-
regexObj.exec(str)
+
regexObj.exec(str)

매개변수

@@ -45,7 +45,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/exec

다음과 같은 예제를 고려해보세요.

-
// Match "quick brown" followed by "jumps", ignoring characters in between
+
// Match "quick brown" followed by "jumps", ignoring characters in between
 // Remember "brown" and "jumps"
 // Ignore case
 let re = /quick\s(brown).+?(jumps)/ig;
@@ -131,7 +131,7 @@ let result = re.exec('The Quick Brown Fox Jumps Over The Lazy Dog');

If your regular expression uses the "g" flag, you can use the exec() method multiple times to find successive matches in the same string. When you do so, the search starts at the substring of str specified by the regular expression's {{jsxref("RegExp.lastIndex", "lastIndex")}} property ({{jsxref("RegExp.prototype.test()", "test()")}} will also advance the {{jsxref("RegExp.lastIndex", "lastIndex")}} property). For example, assume you have this script:

-
var myRe = /ab*/g;
+
var myRe = /ab*/g;
 var str = 'abbcdefabh';
 var myArray;
 while ((myArray = myRe.exec(str)) !== null) {
@@ -143,7 +143,7 @@ while ((myArray = myRe.exec(str)) !== null) {
 
 

This script displays the following text:

-
Found abb. Next match starts at 3
+
Found abb. Next match starts at 3
 Found ab. Next match starts at 9
 
@@ -153,7 +153,7 @@ Found ab. Next match starts at 9

You can also use exec() without creating a {{jsxref("RegExp")}} object:

-
var matches = /(hello \S+)/.exec('This is a hello world!');
+
var matches = /(hello \S+)/.exec('This is a hello world!');
 console.log(matches[1]);
 
diff --git a/files/ko/web/javascript/reference/global_objects/regexp/index.html b/files/ko/web/javascript/reference/global_objects/regexp/index.html index 5675812788..166000e61a 100644 --- a/files/ko/web/javascript/reference/global_objects/regexp/index.html +++ b/files/ko/web/javascript/reference/global_objects/regexp/index.html @@ -29,7 +29,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp

다음의 세 표현식은 모두 같은 정규 표현식을 생성합니다.

-
/ab+c/i
+
/ab+c/i
 new RegExp(/ab+c/, 'i') // 리터럴
 new RegExp('ab+c', 'i') // 생성자
 
@@ -46,7 +46,7 @@ new RegExp('ab+c', 'i') // 생성자

예를 들어 다음 두 줄은 동일한 정규 표현식을 생성합니다.

-
let re = /\w+/
+
let re = /\w+/
 let re = new RegExp('\\w+')

Perl  형태의 RegExp 속성

@@ -121,7 +121,7 @@ let re = new RegExp('\\w+')

대치 문자열에는 $1$2를 사용하여 정규 표현식 패턴의 각 괄호에 일치한 결과를 받아옵니다.

-
let re = /(\w+)\s(\w+)/
+
let re = /(\w+)\s(\w+)/
 let str = 'John Smith'
 let newstr = str.replace(re, '$2, $1')
 console.log(newstr)
@@ -132,7 +132,7 @@ console.log(newstr)

기본 줄 바꿈 문자는 플랫폼(Unix, Windows 등)마다 다릅니다. 아래의 분할 스크립트는 모든 플랫폼의 줄 바꿈을 인식합니다.

-
let text = 'Some text\nAnd some more\r\nAnd yet\rThis is the end'
+
let text = 'Some text\nAnd some more\r\nAnd yet\rThis is the end'
 let lines = text.split(/\r\n|\r|\n/)
 console.log(lines) // logs [ 'Some text', 'And some more', 'And yet', 'This is the end' ]
@@ -140,7 +140,7 @@ console.log(lines) // logs [ 'Some text', 'And some more', 'And yet', 'This is t

여러 줄에서 정규 표현식 사용하기

-
let s = 'Please yes\nmake my day!'
+
let s = 'Please yes\nmake my day!'
 
 s.match(/yes.*day/);
 // Returns null
@@ -152,7 +152,7 @@ s.match(/yes[^]*day/);
 
 

{{JSxRef("Global_Objects/RegExp/sticky", "sticky")}} 플래그는 해당 정규 표현식이 접착 판별, 즉 {{jsxref("RegExp.prototype.lastIndex")}}에서 시작하는 일치만 확인하도록 할 수 있습니다.

-
let str = '#foo#'
+
let str = '#foo#'
 let regex = /foo/y
 
 regex.lastIndex = 1
@@ -165,7 +165,7 @@ regex.lastIndex      // 0 (reset after match failure)

접착 플래그 y의 일치는 정확히 lastIndex 위치에서만 발생할 수 있으나, 전역 플래그 g의 경우 lastIndex 또는 그 이후에서도 발생할 수 있습니다.

-
re = /\d/y;
+
re = /\d/y;
 while (r = re.exec("123 456")) console.log(r, "AND re.lastIndex", re.lastIndex);
 
 // [ '1', index: 0, input: '123 456', groups: undefined ] AND re.lastIndex 1
@@ -181,7 +181,7 @@ while (r = re.exec("123 456")) console.log(r, "AND re.lastIndex", re.lastIndex);
 
 

러시아어나 히브리어와 같은 다른 언어의 문자까지 일치하려면 \uhhhh(이때 hhhh는 해당 문자의 16진법 Unicode 값) 문법을 사용하세요. 아래 예제에서는 문자열에서 Unicode 문자를 추출합니다.

-
let text = 'Образец text на русском языке'
+
let text = 'Образец text на русском языке'
 let regex = /[\u0400-\u04FF]+/g
 
 let match = regex.exec(text)
@@ -198,7 +198,7 @@ console.log(regex.lastIndex) // logs '15'
 
 

URL에서 서브도메인 추출하기

-
let url = 'http://xxx.domain.com'
+
let url = 'http://xxx.domain.com'
 console.log(/[^.]+/.exec(url)[0].substr(7)) // logs 'xxx'
diff --git a/files/ko/web/javascript/reference/global_objects/regexp/regexp/index.html b/files/ko/web/javascript/reference/global_objects/regexp/regexp/index.html index 387b5bceff..a5ed17a62c 100644 --- a/files/ko/web/javascript/reference/global_objects/regexp/regexp/index.html +++ b/files/ko/web/javascript/reference/global_objects/regexp/regexp/index.html @@ -22,7 +22,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/RegExp

리터럴, 생성자, 팩토리 표기법이 가능합니다.

-
/pattern/flags
+
/pattern/flags
 new RegExp(pattern[, flags])
 RegExp(pattern[, flags])
 
@@ -73,7 +73,7 @@ RegExp(pattern[, flags])

다음의 세 표현식은 모두 같은 정규 표현식을 생성합니다.

-
/ab+c/i
+
/ab+c/i
 new RegExp(/ab+c/, 'i') // 리터럴
 new RegExp('ab+c', 'i') // 생성자
 
diff --git a/files/ko/web/javascript/reference/global_objects/regexp/test/index.html b/files/ko/web/javascript/reference/global_objects/regexp/test/index.html index 07569e7eaf..8a4b200e5f 100644 --- a/files/ko/web/javascript/reference/global_objects/regexp/test/index.html +++ b/files/ko/web/javascript/reference/global_objects/regexp/test/index.html @@ -21,7 +21,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/test

구문

-
regexObj.test(str)
+
regexObj.test(str)

매개변수

@@ -48,7 +48,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/test

문자열의 맨 처음에 "hello"가 포함됐는지 알아보는 간단한 예제 코드입니다.

-
const str = 'hello world!';
+
const str = 'hello world!';
 const result = /^hello/.test(str);
 
 console.log(result); // true
@@ -56,7 +56,7 @@ console.log(result); // true
 
 

다음은 일치 여부에 따라 다른 메시지를 기록하는 예제입니다.

-
function testInput(re, str) {
+
function testInput(re, str) {
   let midstring;
   if (re.test(str)) {
     midstring = 'contains';
@@ -81,7 +81,7 @@ console.log(result); // true
 
 

이 행동에 대한 예제가 다음 코드입니다.

-
const regex = /foo/g; // the "global" flag is set
+
const regex = /foo/g; // the "global" flag is set
 
 // regex.lastIndex is at 0
 regex.test('foo')     // true
diff --git a/files/ko/web/javascript/reference/global_objects/string/lastindexof/index.html b/files/ko/web/javascript/reference/global_objects/string/lastindexof/index.html
index d2244feee5..90aeaf3af0 100644
--- a/files/ko/web/javascript/reference/global_objects/string/lastindexof/index.html
+++ b/files/ko/web/javascript/reference/global_objects/string/lastindexof/index.html
@@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/lastIndexOf
 
 

구문

-
str.lastIndexOf(searchValue[, fromIndex])
+
str.lastIndexOf(searchValue[, fromIndex])

매개변수

@@ -38,7 +38,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/lastIndexOf

문자열의 문자는 왼쪽에서 오른쪽으로 인덱스를 매깁니다. 첫 번째 문자의 인덱스는 0이며, 마지막 문자의 인덱스는 str.length -1입니다.

-
'canal'.lastIndexOf('a');     //  3 반환
+
'canal'.lastIndexOf('a');     //  3 반환
 'canal'.lastIndexOf('a', 2);  //  1 반환
 'canal'.lastIndexOf('a', 0);  // -1 반환
 'canal'.lastIndexOf('x');     // -1 반환
@@ -56,7 +56,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/lastIndexOf
 
 

lastIndexOf() 메서드는 대소문자를 구분합니다. 예를 들어, 아래 예제는 -1을 반환합니다.

-
'Blue Whale, Killer Whale'.lastIndexOf('blue'); // -1 반환
+
'Blue Whale, Killer Whale'.lastIndexOf('blue'); // -1 반환
 

예제

@@ -65,7 +65,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/lastIndexOf

아래 예제는 문자열 "Brave new world" 내에서 특정 값의 위치를 확인하기 위해 {{jsxref("String.prototype.indexOf()", "indexOf()")}}와 lastIndexOf()를 사용합니다.

-
let anyString = 'Brave new world';
+
let anyString = 'Brave new world';
 
 console.log('시작점으로부터 처음 만나는 w의 위치는 ' + anyString.indexOf('w'));
 // logs 8
diff --git a/files/ko/web/javascript/reference/global_objects/string/slice/index.html b/files/ko/web/javascript/reference/global_objects/string/slice/index.html
index 3bd23ace3b..6c0c54a50b 100644
--- a/files/ko/web/javascript/reference/global_objects/string/slice/index.html
+++ b/files/ko/web/javascript/reference/global_objects/string/slice/index.html
@@ -16,7 +16,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/slice
 
 

문법

-
str.slice(beginIndex[, endIndex])
+
str.slice(beginIndex[, endIndex])

매개변수

@@ -47,7 +47,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/slice

아래 예시는 새 문자열을 생성하기 위해 slice()를 사용합니다.

-
var str1 = 'The morning is upon us.', // the length of str1 is 23.
+
var str1 = 'The morning is upon us.', // the length of str1 is 23.
     str2 = str1.slice(1, 8),
     str3 = str1.slice(4, -2),
     str4 = str1.slice(12),
@@ -62,7 +62,7 @@ console.log(str5); // OUTPUT: ""
 
 

아래 예시는 slice()에 음수 인덱스를 사용합니다.

-
var str = 'The morning is upon us.';
+
var str = 'The morning is upon us.';
 str.slice(-3);     // returns 'us.'
 str.slice(-3, -1); // returns 'us'
 str.slice(0, -1);  // returns 'The morning is upon us'
@@ -70,16 +70,16 @@ str.slice(0, -1);  // returns 'The morning is upon us'
 
 

아래의 예시는 시작 인덱스를 찾기 위해 문자열의 끝에서부터 역방향으로 11개를 세고 끝 인덱스를 찾기 위해 문자열의 시작에서부터 정방향으로 16개를 셉니다.

-
console.log(str.slice(-11, 16)) // => "is u";
+
console.log(str.slice(-11, 16)) // => "is u";

아래에서는 시작 인덱스를 찾기 위해 문자열의 처음부터 정방향으로 11개를 세고 끝 인덱스를 찾기 위해 끝에서부터 7개를 셉니다.

-
console.log(str.slice(11, -7)) // => "is u";
+
console.log(str.slice(11, -7)) // => "is u";
 

이 인수는 끝에서부터 5로 역순으로 계산하여 시작 인덱스를 찾은 다음 끝에서부터 1을 거쳐 끝 인덱스를 찾습니다.

-
console.log(str.slice(-5, -1)) // => "n us";
+
console.log(str.slice(-5, -1)) // => "n us";
 

Specifications

diff --git a/files/ko/web/javascript/reference/global_objects/undefined/index.html b/files/ko/web/javascript/reference/global_objects/undefined/index.html index ca11856dc0..eb75867c9a 100644 --- a/files/ko/web/javascript/reference/global_objects/undefined/index.html +++ b/files/ko/web/javascript/reference/global_objects/undefined/index.html @@ -16,7 +16,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/undefined

구문

-
undefined
+
undefined

설명

@@ -29,7 +29,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/undefined

undefined예약어가 아니기 때문에 전역 범위 외에서 {{Glossary("Identifier", "식별자")}}(변수 이름)로 사용할 수 있습니다. 그러나 유지보수와 디버깅 시 어려움을 낳을 수 있으므로 반드시 피해야 합니다.

-
//  DON'T DO THIS
+
//  DON'T DO THIS
 
 //  logs "foo string"
 (function() {
@@ -49,7 +49,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/undefined
 
 

undefined와 일치, 불일치 연산자를 사용해 변수에 값이 할당됐는지 판별할 수 있습니다. 다음 예제에서 변수 x는 초기화되지 않았으므로 if문은 true로 평가됩니다.

-
var x;
+
var x;
 if (x === undefined) {
    // 이 문이 실행됨
 }
@@ -68,7 +68,7 @@ else {
 
 

위의 예제 대신 {{jsxref("Operators/typeof", "typeof")}}를 사용할 수도 있습니다.

-
var x;
+
var x;
 if (typeof x === 'undefined') {
    // 이 문이 실행됨
 }
@@ -76,7 +76,7 @@ if (typeof x === 'undefined') {
 
 

typeof를 사용하는 이유 중 하나는 선언하지 않은 변수를 사용해도 오류를 던지지 않기 때문입니다.

-
// x를 선언한 적 없음
+
// x를 선언한 적 없음
 if (typeof x === 'undefined') { // 오류 없이 true로 평가
    // 이 문이 실행됨
 }
@@ -90,7 +90,7 @@ if(x === undefined) { // ReferenceError
 
 

전역 범위는 {{jsxref("globalThis", "전역 객체", "", 1)}}에 묶여 있으므로, 전역 맥락에서 변수의 존재 유무는 {{jsxref("Operators/in", "in")}} 연산자를 전역 객체 대상으로 실행해 알 수 있습니다. 즉,

-
if ('x' in window) {
+
if ('x' in window) {
   //  x가 전역으로 정의된 경우 이 문이 실행됨
 }
@@ -98,7 +98,7 @@ if(x === undefined) { // ReferenceError

{{jsxref("Operators/void", "void")}} 연산자를 제 3의 대안으로 사용할 수 있습니다.

-
var x;
+
var x;
 if (x === void 0) {
    // 이 문이 실행됨
 }
diff --git a/files/ko/web/javascript/reference/lexical_grammar/index.html b/files/ko/web/javascript/reference/lexical_grammar/index.html
index 1f2349bc1a..c127dcd69c 100644
--- a/files/ko/web/javascript/reference/lexical_grammar/index.html
+++ b/files/ko/web/javascript/reference/lexical_grammar/index.html
@@ -166,7 +166,7 @@ translation_of: Web/JavaScript/Reference/Lexical_grammar
 
 

첫 번째, '//'로 첨언하기입니다. 이는 아래의 예시처럼 같은 줄에 있는 모든 코드를 주석으로 바꿉니다.

-
function comment() {
+
function comment() {
   // 자바스크립트의 각주 한 줄입니다.
   console.log("Hello world!");
 }
@@ -177,7 +177,7 @@ comment();
 
 

예를 들면, 한 줄에 첨언할 때는 이렇게 쓸 수 있습니다 :

-
function comment() {
+
function comment() {
   /* 자바스크립트 각주 한 줄입니다. */
   console.log("Hello world!");
 }
@@ -185,7 +185,7 @@ comment();

여러 줄로 첨언할 때는, 이렇게 씁니다 :

-
function comment() {
+
function comment() {
   /* This comment spans multiple lines. Notice
      that we don't need to end the comment until we're done. */
   console.log("Hello world!");
@@ -196,13 +196,13 @@ comment();

function comment(x) {

-
  console.log("Hello " + x /* insert the value of x */ + " !");
+
  console.log("Hello " + x /* insert the value of x */ + " !");
 }
 comment("world");

게다가, 코드 실행을 막기 위해 코드를 무용화 시키는데도 사용할 수 있습니다. 아래처럼 코드를 코멘트로 감싸는 거죠:

-
function comment() {
+
function comment() {
   /* console.log("Hello world!"); */
 }
 comment();
@@ -218,7 +218,7 @@ comment();

The hashbang comment specifies the path to a specific JavaScript interpreter
that you want to use to execute the script. An example is as follows:

-
#!/usr/bin/env node
+
#!/usr/bin/env node
 
 console.log("Hello world");
 
@@ -331,14 +331,14 @@ console.log("Hello world");

Reserved words actually only apply to Identifiers (vs. IdentifierNames) . As described in es5.github.com/#A.1, these are all IdentifierNames which do not exclude ReservedWords.

-
a.import
+
a.import
 a['import']
 a = { import: 'test' }.
 

On the other hand the following is illegal because it's an Identifier, which is an IdentifierName without the reserved words. Identifiers are used for FunctionDeclaration, FunctionExpression, VariableDeclaration and so on. IdentifierNames are used for MemberExpression, CallExpression and so on.

-
function import() {} // Illegal.
+
function import() {} // Illegal.

리터럴

@@ -346,20 +346,20 @@ a = { import: 'test' }.

See also null for more information.

-
null
+
null

불리언 리터럴

See also Boolean for more information.

-
true
+
true
 false

숫자 리터럴

10진법

-
1234567890
+
1234567890
 42
 
 // Caution when using with a leading zero:
@@ -373,7 +373,7 @@ false

The decimal exponential literal is specified by the following format: beN; where b is a base number (integer or floating), followed by e char (which serves as separator or exponent indicator) and N, which is exponent or power number – a signed integer (as per 2019 ECMA-262 specs): 

-
0e-5   // => 0
+
0e-5   // => 0
 0e+5   // => 0
 5e1    // => 50
 175e-2 // => 1.75
@@ -384,7 +384,7 @@ false

Binary number syntax uses a leading zero followed by a lowercase or uppercase Latin letter "B" (0b or 0B). Because this syntax is new in ECMAScript 2015, see the browser compatibility table, below. If the digits after the 0b are not 0 or 1, the following SyntaxError is thrown: "Missing binary digits after 0b".

-
var FLT_SIGNBIT  = 0b10000000000000000000000000000000; // 2147483648
+
var FLT_SIGNBIT  = 0b10000000000000000000000000000000; // 2147483648
 var FLT_EXPONENT = 0b01111111100000000000000000000000; // 2139095040
 var FLT_MANTISSA = 0B00000000011111111111111111111111; // 8388607
@@ -392,7 +392,7 @@ var FLT_MANTISSA = 0B00000000011111111111111111111111; // 8388607

Octal number syntax uses a leading zero followed by a lowercase or uppercase Latin letter "O" (0o or 0O). Because this syntax is new in ECMAScript 2015, see the browser compatibility table, below. If the digits after the 0o are outside the range (01234567), the following SyntaxError is thrown: "Missing octal digits after 0o".

-
var n = 0O755; // 493
+
var n = 0O755; // 493
 var m = 0o644; // 420
 
 // Also possible with just a leading zero (see note about decimals above)
@@ -404,7 +404,7 @@ var m = 0o644; // 420
 
 

Hexadecimal number syntax uses a leading zero followed by a lowercase or uppercase Latin letter "X" (0x or 0X). If the digits after 0x are outside the range (0123456789ABCDEF), the following SyntaxError is thrown: "Identifier starts immediately after numeric literal".

-
0xFFFFFFFFFFFFFFFFF // 295147905179352830000
+
0xFFFFFFFFFFFFFFFFF // 295147905179352830000
 0x123456789ABCDEF   // 81985529216486900
 0XA                 // 10
 
@@ -413,7 +413,7 @@ var m = 0o644; // 420

The {{jsxref("BigInt")}} type is a numeric primitive in JavaScript that can represent integers with arbitrary precision. BigInt literals are created by appending n to the end of an integer.

-
123456789123456789n     // 123456789123456789
+
123456789123456789n     // 123456789123456789
 0o777777777777n         // 68719476735
 0x123456789ABCDEFn      // 81985529216486895‬
 0b11101001010101010101n // 955733
@@ -421,12 +421,12 @@ var m = 0o644; // 420
 
 

Note that legacy octal numbers with just a leading zero won't work for BigInt:

-
// 0755n
+
// 0755n
 // SyntaxError: invalid BigInt syntax

For octal BigInt numbers, always use zero followed by the letter "o" (uppercase or lowercase):

-
0o755n
+
0o755n

For more information about BigInt, see also JavaScript data structures.

@@ -434,7 +434,7 @@ var m = 0o644; // 420

To improve readability for numeric literals, underscores (_U+005F) can be used as separators:

-
// separators in decimal numbers
+
// separators in decimal numbers
 1_000_000_000_000
 1_050.95
 
@@ -453,7 +453,7 @@ var m = 0o644; // 420
 
 

Note these limitations:

-
// More than one underscore in a row is not allowed
+
// More than one underscore in a row is not allowed
 100__000; // SyntaxError
 
 // Not allowed at the end of numeric literals
@@ -467,7 +467,7 @@ var m = 0o644; // 420
 
 

See also {{jsxref("Object")}} and Object initializer for more information.

-
var o = { a: 'foo', b: 'bar', c: 42 };
+
var o = { a: 'foo', b: 'bar', c: 42 };
 
 // shorthand notation. New in ES2015
 var a = 'foo', b = 'bar', c = 42;
@@ -481,7 +481,7 @@ var o = { a: a, b: b, c: c };
 
 

See also {{jsxref("Array")}} for more information.

-
[1954, 1974, 1990, 2014]
+
[1954, 1974, 1990, 2014]

문자열 리터럴

@@ -497,14 +497,14 @@ var o = { a: a, b: b, c: c };

Any code points may appear in the form of an escape sequence. String literals evaluate to ECMAScript String values. When generating these String values Unicode code points are UTF-16 encoded.

-
'foo'
+
'foo'
 "bar"

16진수 이스케이프 시퀀스

Hexadecimal escape sequences consist of \x followed by exactly two hexadecimal digits representing a code unit or code point in the range 0x0000 to 0x00FF.

-
'\xA9' // "©"
+
'\xA9' // "©"
 

유니코드 이스케이프 시퀀스

@@ -513,7 +513,7 @@ var o = { a: a, b: b, c: c };

See also {{jsxref("String.fromCharCode()")}} and {{jsxref("String.prototype.charCodeAt()")}}.

-
'\u00A9' // "©" (U+A9)
+
'\u00A9' // "©" (U+A9)

유니코드 코드 포인트 시퀀스

@@ -521,7 +521,7 @@ var o = { a: a, b: b, c: c };

See also {{jsxref("String.fromCodePoint()")}} and {{jsxref("String.prototype.codePointAt()")}}.

-
'\u{2F804}' // CJK COMPATIBILITY IDEOGRAPH-2F804 (U+2F804)
+
'\u{2F804}' // CJK COMPATIBILITY IDEOGRAPH-2F804 (U+2F804)
 
 // the same character represented as a surrogate pair
 '\uD87E\uDC04'
@@ -530,7 +530,7 @@ var o = { a: a, b: b, c: c };

See also RegExp for more information.

-
/ab+c/g
+
/ab+c/g
 
 // An "empty" regular expression literal
 // The empty non-capturing group is necessary
@@ -541,7 +541,7 @@ var o = { a: a, b: b, c: c };
 
 

See also template strings for more information.

-
`string text`
+
`string text`
 
 `string text line 1
  string text line 2`
@@ -568,7 +568,7 @@ tag `string text ${expression} string text`

1. A semicolon is inserted before, when a Line terminator or "}" is encountered that is not allowed by the grammar.

-
{ 1 2 } 3
+
{ 1 2 } 3
 
 // is transformed by ASI into
 
@@ -578,7 +578,7 @@ tag `string text ${expression} string text`

Here ++ is not treated as a postfix operator applying to variable b, because a line terminator occurs between b and ++.

-
a = b
+
a = b
 ++c
 
 // is transformend by ASI into
@@ -598,7 +598,7 @@ a = b;
  
  • module
  • -
    return
    +
    return
     a + b
     
     // is transformed by ASI into
    diff --git a/files/ko/web/javascript/reference/operators/await/index.html b/files/ko/web/javascript/reference/operators/await/index.html
    index 00b5fd3eff..4087edfca7 100644
    --- a/files/ko/web/javascript/reference/operators/await/index.html
    +++ b/files/ko/web/javascript/reference/operators/await/index.html
    @@ -9,7 +9,7 @@ translation_of: Web/JavaScript/Reference/Operators/await
     
     

    구문

    -
    [rv] = await expression;
    +
    [rv] = await expression;
    expression
    @@ -34,7 +34,7 @@ translation_of: Web/JavaScript/Reference/Operators/await

    만약 Promiseawait에 넘겨지면, awaitPromise가 fulfill되기를 기다렸다가, 해당 값을 리턴합니다.

    -
    function resolveAfter2Seconds(x) {
    +
    function resolveAfter2Seconds(x) {
       return new Promise(resolve => {
         setTimeout(() => {
           resolve(x);
    @@ -52,7 +52,7 @@ f1();
     
     

    {{jsxref("Global_Objects/Promise/then", "Thenable objects")}} will be fulfilled just the same.

    -
    async function f2() {
    +
    async function f2() {
       const thenable = {
         then: function(resolve, _reject) {
           resolve('resolved!')
    @@ -65,7 +65,7 @@ f2();

    만약 값이 Promise가 아니라면, 해당 값은 resolvePromise로 변환되며 이를 기다립니다.

    -
    async function f2() {
    +
    async function f2() {
       var y = await 20;
       console.log(y); // 20
     }
    @@ -74,7 +74,7 @@ f2();
     
     

    만약 Promisereject되면, reject된 값이 throw됩니다.

    -
    async function f3() {
    +
    async function f3() {
       try {
         var z = await Promise.reject(30);
       } catch(e) {
    @@ -86,7 +86,7 @@ f3();
     
     

    try블럭 없이 rejected Promise다루기

    -
    var response = await promisedFunction().catch((err) => { console.error(err); });
    +
    var response = await promisedFunction().catch((err) => { console.error(err); });
     // response will be undefined if the promise is rejected

    Specifications

    -- cgit v1.2.3-54-g00ecf