diff options
author | 3indblown Leaf <69508345+kraccoon-dev@users.noreply.github.com> | 2022-02-01 19:42:11 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-01 19:42:11 +0900 |
commit | 4289bf1fbb823f410775b4c7d0533b7abd8e5f5f (patch) | |
tree | 624a9bf236fff00b97fc8c61a76b672333303427 /files/ko/web/javascript/reference/functions | |
parent | 41bbbf1ce8a34763e6ecc099675af29fb5bef62e (diff) | |
download | translated-content-4289bf1fbb823f410775b4c7d0533b7abd8e5f5f.tar.gz translated-content-4289bf1fbb823f410775b4c7d0533b7abd8e5f5f.tar.bz2 translated-content-4289bf1fbb823f410775b4c7d0533b7abd8e5f5f.zip |
remove class 1 (#3922)
Diffstat (limited to 'files/ko/web/javascript/reference/functions')
-rw-r--r-- | files/ko/web/javascript/reference/functions/arrow_functions/index.html | 44 | ||||
-rw-r--r-- | files/ko/web/javascript/reference/functions/default_parameters/index.html | 26 |
2 files changed, 35 insertions, 35 deletions
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/애로우_펑션 <h3 id="기본_구문">기본 구문</h3> -<pre class="syntaxbox notranslate"><strong>(</strong><em>param1</em>, <em>param2</em>, …, <em>paramN</em><strong>) => {</strong> <em>statements</em> <strong>}</strong> +<pre class="syntaxbox "><strong>(</strong><em>param1</em>, <em>param2</em>, …, <em>paramN</em><strong>) => {</strong> <em>statements</em> <strong>}</strong> <strong>(</strong><em>param1</em>, <em>param2</em>, …, <em>paramN</em><strong>) =></strong> <em>expression</em> // 다음과 동일함: => { return expression; } @@ -40,7 +40,7 @@ original_slug: Web/JavaScript/Reference/Functions/애로우_펑션 <h3 id="고급_구문">고급 구문</h3> -<pre class="syntaxbox notranslate">// 객체 리터럴 표현을 반환하기 위해서는 함수 본문(body)을 괄호 속에 넣음: +<pre class="syntaxbox ">// 객체 리터럴 표현을 반환하기 위해서는 함수 본문(body)을 괄호 속에 넣음: <em>params</em> => ({<em>foo: bar</em>}) // <a href="/ko/docs/Web/JavaScript/Reference/Functions/rest_parameters">나머지 매개변수</a> 및 <a href="/ko/docs/Web/JavaScript/Reference/Functions/Default_parameters">기본 매개변수</a>를 지원함 @@ -64,7 +64,7 @@ f(); // 6 <p>일부 함수 패턴에서는, 짧은 함수가 환영받습니다. 비교해 보세요:</p> -<pre class="notranslate">var elements = [ +<pre >var elements = [ 'Hydrogen', 'Helium', 'Lithium', @@ -114,7 +114,7 @@ elements.<a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map" <p>이는 객체 지향 스타일로 프로그래밍할 때 별로 좋지않습니다.</p> -<pre class="brush: js notranslate">function Person() { +<pre class="brush: js ">function Person() { // Person() 생성자는 `this`를 자신의 인스턴스로 정의. this.age = 0; @@ -130,7 +130,7 @@ var p = new Person();</pre> <p>ECMAScript 3/5 에서는, 이 문제를 <code>this</code> 값을 폐쇄될 수 있는 (비전역) 변수에 할당하여 해결했습니다.</p> -<pre class="brush: js notranslate">function Person() { +<pre class="brush: js ">function Person() { var that = this; that.age = 0; @@ -146,7 +146,7 @@ var p = new Person();</pre> <p>따라서 다음 코드에서 <code>setInterval</code>에 전달 된 함수 내부의 <code>this</code>는 <code>setInterval</code>을 포함한 function의 <code>this</code>와 동일한 값을 갖습니다.</p> -<pre class="brush: js notranslate">function Person(){ +<pre class="brush: js ">function Person(){ this.age = 0; setInterval(() => { @@ -160,7 +160,7 @@ var p = new Person();</pre> <p><code>this</code>가 렉시컬(lexical, 정적)임을 감안하면, <code>this</code>에 관한 <a href="/ko/docs/Web/JavaScript/Reference/Strict_mode">엄격 모드</a> 규칙은 그냥 무시됩니다.</p> -<pre class="notranslate">var f = () => { 'use strict'; return this; }; +<pre >var f = () => { 'use strict'; return this; }; f() === window; // 혹은 전역객체</pre> <p>엄격 모드의 나머지 규칙은 평소대로 적용합니다.</p> @@ -173,7 +173,7 @@ f() === window; // 혹은 전역객체</pre> <p>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):</p> -<pre class="notranslate">> f1 = x => { y = x; console.log(`x: ${x}, y: ${y}`); return x + 1; } +<pre >> 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 <p>화살표 함수에서는 <code>this가 </code> 바인딩되지 않았기 때문에, <code>call()</code> 또는 <code>apply()</code> 메서드는 인자만 전달 할 수 있습니다. this는 무시됩니다.</p> -<pre class="brush: js notranslate">var adder = { +<pre class="brush: js ">var adder = { base : 1, add : function(a) { @@ -255,7 +255,7 @@ console.log(adder.addThruCall(1)); // 이도 2가 콘솔에 출력될 것임</pr <p>화살표 함수는 <a href="/ko/docs/Web/JavaScript/Reference/Functions/arguments"><code>arguments</code> 객체</a>를 바인드 하지 않습니다. 때문에, <code>arguments는</code> 그저 둘러싸는 범위(scope) 내 이름에 대한 참조입니다.</p> -<pre class="brush: js notranslate"><code>var arguments = [1, 2, 3]; +<pre class="brush: js "><code>var arguments = [1, 2, 3]; var arr = () => arguments[0]; arr(); // 1 @@ -269,7 +269,7 @@ foo(1); // 2</code></pre> <p>화살표 함수는 자신의 <code>arguments</code> 객체가 없지만, 대부분의 경우에 <a href="/ko/docs/Web/JavaScript/Reference/Functions/rest_parameters">나머지 매개변수</a>가 좋은 대안입니다:</p> -<pre class="brush: js notranslate">function foo(n) { +<pre class="brush: js ">function foo(n) { var f = (...args) => args[0] + n; return f(2); } @@ -280,7 +280,7 @@ foo(1); // 3</pre> <p>이야기 했듯이, 화살표 함수 표현은 메소드 함수가 아닌 형태로 사용 할 수 있습니다. 메소드로 사용하려고 한면 무슨일이 발생하는지 봅시다.</p> -<pre class="brush: js notranslate"><code>'use strict'; +<pre class="brush: js "><code>'use strict'; var obj = { // does not create a new scope i: 10, @@ -295,7 +295,7 @@ obj.c(); // prints 10, Object {...}</code> <p>화살표 함수는 자신의 this를 가지고("bind" 바인드)있지 않습니다.{{jsxref("Object.defineProperty()")}}</p> -<pre class="brush: js notranslate"><code>'use strict'; +<pre class="brush: js "><code>'use strict'; var obj = { a: 10 @@ -312,14 +312,14 @@ Object.defineProperty(obj, 'b', { <p>화살표 함수는 생성자로서 사용될 수 없으며 <code>new</code>와 함께 사용하면 오류가 발생합니다.</p> -<pre class="brush: js notranslate"><code>var Foo = () => {}; +<pre class="brush: js "><code>var Foo = () => {}; var foo = new Foo(); // TypeError: Foo is not a constructor</code></pre> <h3 id="prototype_속성_사용"><code>prototype</code> 속성 사용</h3> <p>화살표 함수는 <code>prototype</code> 속성이 없습니다.</p> -<pre class="brush: js notranslate"><code>var Foo = () => {}; +<pre class="brush: js "><code>var Foo = () => {}; console.log(Foo.prototype); // undefined</code></pre> <h3 id="yield_키워드_사용"><code>yield</code> 키워드 사용</h3> @@ -336,7 +336,7 @@ console.log(Foo.prototype); // undefined</code></pre> <p>block바디는 자동으로 값을 반환하지 않습니다. <code>return</code>을 사용해서 값을 반환해야 합니다.</p> -<pre class="brush: js notranslate">var func = x => x * x; // concise 바디, 생략된 "return" 여기서는 x * x +<pre class="brush: js ">var func = x => x * x; // concise 바디, 생략된 "return" 여기서는 x * x var func = (x, y) => { return x + y; }; // block 바디, "return"이 필요 </pre> @@ -344,7 +344,7 @@ var func = (x, y) => { return x + y; }; // block 바디, "return"이 필요 <p>간결한 구문 <code>params => {object:literal}</code>을 사용한 객체 리터럴 반환은 예상대로 작동하지 않음을 명심하세요:</p> -<pre class="brush: js notranslate">var func = () => { foo: 1 }; +<pre class="brush: js ">var func = () => { foo: 1 }; // func() 호출은 undefined를 반환! var func = () => { foo: function() {} }; @@ -354,19 +354,19 @@ var func = () => { foo: function() {} }; <p>객체 리터럴를 괄호로 감싸는 것을 기억하세요:</p> -<pre class="brush: js notranslate">var func = () => ({ foo: 1 });</pre> +<pre class="brush: js ">var func = () => ({ foo: 1 });</pre> <h3 id="줄바꿈">줄바꿈</h3> <p>화살표 함수는 파라메터와 화살표 사이에 개행 문자를 포함 할 수 없습니다.</p> -<pre class="brush: js notranslate"><code>var func = (a, b, c) +<pre class="brush: js "><code>var func = (a, b, c) => 1; // SyntaxError: expected expression, got '=>'</code></pre> <p>하지만, 보기 좋은 코드를 유지하고 싶다면, 아래에 보는 것처럼 괄호나 개행을 둠으로써 이를 수정할 수 있습니다.</p> -<pre class="notranslate">var func = (a, b, c) => +<pre >var func = (a, b, c) => 1; var func = (a, b, c) => ( @@ -389,7 +389,7 @@ var func = (a, b, c) => { <p>화살표 함수 내의 화살표는 연산자가 아닙니다. 그러나 화살표 함수는 평범한 함수와 비교했을 때 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence">operator precedence</a>와 다르게 반응하는 특별한 파싱룰을 가지고 있습니다.</p> -<pre class="brush: js notranslate"><code>let callback; +<pre class="brush: js "><code>let callback; callback = callback || function() {}; // ok @@ -403,7 +403,7 @@ callback = callback || (() => {}); // ok</code> <h3 id="기본_사용법">기본 사용법</h3> -<pre class="brush: js notranslate"><code>// </code> empty 화살표 함수는 undefined를 반환 <code> +<pre class="brush: js "><code>// </code> empty 화살표 함수는 undefined를 반환 <code> 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 <h2 id="구문">구문</h2> -<pre class="brush: js notranslate"> +<pre class="brush: js "> function fnName(param1 = defaultValue1, ..., paramN = defaultValueN) { ... } </pre> @@ -29,7 +29,7 @@ function fnName(param1 = defaultValue1, ..., paramN = defaultValueN) { ... } <p>다음 예제에서, <code>multiply</code>호출시 <code>b</code>에 할당된 값이 없다면, <code>b</code> 값은 <code>a*b</code>를 평가할 때 <code>undefined</code>일 거고 <code>multiply</code> 호출은 <code>NaN</code>이 반환됩니다. </p> -<pre class="brush: js notranslate">function multiply(a, b) { +<pre class="brush: js ">function multiply(a, b) { return a * b } @@ -39,7 +39,7 @@ multiply(5) // NaN ! <p>이를 방지하기 위해서, 아래 두번째 줄과 같이 <code>multiply</code> 함수가 오직 한 개의 인수만 있다면 <code>b</code>를 <code>1</code>로 설정하는 방식을 사용하곤 했습니다.</p> -<pre class="brush: js notranslate">function multiply(a, b) { +<pre class="brush: js ">function multiply(a, b) { b = (typeof b !== 'undefined') ? b : 1 return a*b } @@ -50,7 +50,7 @@ multiply(5) // 5 <p>ES2015의 기본값 매개변수로 함수 내부 에서의 검사는 더 이상 필요치 않습니다. 이제, 간단히 함수 머리(head)에서 <code>b</code>의 기본값으로 <code>1</code> 로 설정할 수 있습니다:</p> -<pre class="brush: js notranslate">function multiply(a, b = 1) { +<pre class="brush: js ">function multiply(a, b = 1) { return a*b } @@ -65,7 +65,7 @@ multiply(5, undefined) // 5 <p>아래 예제중 두 번째 호출에서, 설사 두 번째 인수를 호출할 때 명시해서 <code>undefined</code> (<code>null</code> 혹은 {{glossary("falsy")}} 값이 아니긴 하지만 )로 설정하더라도 , <code>num</code> 인수의 값은 여전히 기본값입니다.</p> -<pre class="brush: js notranslate">function test(num = 1) { +<pre class="brush: js ">function test(num = 1) { console.log(typeof num) } @@ -81,7 +81,7 @@ test(null) // 'object' (num 은 null로 설정됨) <p>기본 인수는 <em>호출</em> <em>시 </em>에 평가됩니다, 그래서 Python의 경우 와는 달리, 함수가 호출될 때마다 새로운 객체가 생성됩니다.</p> -<pre class="brush: js notranslate">function append(value, array = []) { +<pre class="brush: js ">function append(value, array = []) { array.push(value) return array } @@ -93,7 +93,7 @@ append(2) // [2], [1, 2]가 아니라 <p>이는 심지어 함수 및 변수에도 적용됩니다:</p> -<pre class="brush: js notranslate">function callSomething(thing = something()) { +<pre class="brush: js ">function callSomething(thing = something()) { return thing } @@ -111,7 +111,7 @@ callSomething() // 2 <p>매개 변수가 여러개일 때 앞쪽에( 왼쪽 부분) 정의된 매개변수는 뒷쪽에 정의된 매개변수의 기본값에 바로 사용할 수 있습니다.</p> -<pre class="brush: js notranslate">function greet(name, greeting, message = greeting + ' ' + name) { +<pre class="brush: js ">function greet(name, greeting, message = greeting + ' ' + name) { return [name, greeting, message] } @@ -121,7 +121,7 @@ greet('David', 'Hi', 'Happy Birthday!') // ["David", "Hi", "Happy Birthday!"] <p>이 기능은, 얼마나 많은 경계 조건(edge case)를 다룰수 있는지 보여주는, 아래 예제로 거의 설명 가능합니다.</p> -<pre class="brush: js notranslate">function go() { +<pre class="brush: js ">function go() { return ':P' } @@ -172,13 +172,13 @@ withoutDefaults.call({value:"=^_^="}); <p>아래 함수는 호출되면 <code>ReferenceError</code> 를 발생시킵니다. 매개변수 기본값이 함수 내부의 자식 유효범위를 참조할 수 없기 때문입니다.</p> -<pre class="brush: js example-bad notranslate">function f(a = go()) { // `f`가 호출 되면 `ReferenceError` 발생 +<pre class="brush: js example-bad ">function f(a = go()) { // `f`가 호출 되면 `ReferenceError` 발생 function go() { return ':P' } }</pre> <p>...그리고 아래 함수는 <code>undefined</code> 를 프린트 하는데, <code>var a</code> 가 함수 내부 대상의 유효범위내에서만 효과를 가지기 때문입니다. ( 매개변수 목록이 대상인 부모 스코프가 아니라)</p> -<pre class="brush: js example-bad notranslate">function f(a, b = () => console.log(a)) { +<pre class="brush: js example-bad ">function f(a, b = () => console.log(a)) { var a = 1 b() // `undefined`를 인쇄하는데, 매개변수 기본값이 자체 스코프에 있기 때문입니다 } </pre> @@ -187,7 +187,7 @@ withoutDefaults.call({value:"=^_^="}); <p>매개변수는 여전히 왼쪽에서 오른쪽으로 설정됩니다. 아래 예제에서 뒷쪽에 기본값이 없는 매개변수가 있지만 기본값 매개변수를 덮어씁니다.</p> -<pre class="brush: js notranslate">function f(x=1, y) { +<pre class="brush: js ">function f(x=1, y) { return [x, y]; } @@ -199,7 +199,7 @@ f(2) // [2, undefined] <p>기본값 할당을 {{jsxref("Operators/Destructuring_assignment", "destructuring assignment", "", 1)}} 표기와 함께 사용할 수 있습니다:</p> -<pre class="brush: js notranslate">function f([x, y] = [1, 2], {z: z} = {z: 3}) { +<pre class="brush: js ">function f([x, y] = [1, 2], {z: z} = {z: 3}) { return x + y + z } |