diff options
Diffstat (limited to 'files/ko/web/javascript/reference/global_objects')
14 files changed, 72 insertions, 72 deletions
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를 반환 <p><code>eval</code>을 사용하는 나쁜 코드:</p> -<pre class="brush:js notranslate">function looseJsonParse(obj){ +<pre class="brush:js ">function looseJsonParse(obj){ return eval(obj); } console.log(looseJsonParse( @@ -82,7 +82,7 @@ console.log(looseJsonParse( <p><code>eval</code>이 없는 코드:</p> -<pre class="brush:js notranslate">function looseJsonParse(obj){ +<pre class="brush:js ">function looseJsonParse(obj){ return Function('"use strict";return (' + obj + ')')(); } console.log(looseJsonParse( @@ -92,7 +92,7 @@ console.log(looseJsonParse( <p>위의 두 코드는 얼핏 보면 같은 방식으로 실행되는 것처럼 보이지만, <code>eval</code>이 있는 코드가 훨씬 느립니다. 평가되는 객체의 <code>c: new Date()</code>를 주목하세요. <code>eval</code>이 없는 함수의 경우 이 객체는 전역 범위에서 평가되기 때문에 브라우저에서는 <code>Date</code>를 같은 이름의 지역 변수가 아니라 <code>window.Date</code>로 취급할 수 있습니다. 그러나 <code>eval()</code>을 사용하는 코드에서는 아래와 같은 경우도 존재할 수 있기 때문에 <code>Date</code>를 이렇게 취급할 수 없습니다.</p> -<pre class="brush:js notranslate">function Date(n){ +<pre class="brush:js ">function Date(n){ return ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"][n%7 || 0]; } function looseJsonParse(obj){ @@ -107,7 +107,7 @@ console.log(looseJsonParse( <p>만약 위의 상황에서 실제로 새로 선언한 <code>Date</code> 함수를 <code>Function()</code>에서 실행해야 하는 상황을 생각해 봅시다. 이렇게 되면 <code>eval()</code>로 돌아가야 할까요? 물론 아닙니다. 아래의 접근을 시도해 보세요.</p> -<pre class="brush:js notranslate">function Date(n){ +<pre class="brush:js ">function Date(n){ return ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"][n%7 || 0]; } function runCodeWithDateFunction(obj){ @@ -132,7 +132,7 @@ console.log(runCodeWithDateFunction( <p>마지막으로 코드 최소화의 측면에서 살펴보면, 위와 같이 <code>Function()</code>을 사용했을 때는 아래의 최소화된 코드와 같이 함수의 인자 이름 역시 짧게 줄일 수 있으므로 runCodeWithDateFunction에 전달하는 코드 문자열을 더욱 효율적으로 줄일 수 있습니다.</p> -<pre class="brush:js notranslate">console.log(Function('"use strict";return(function(a){return a(5)})')()(function(a){ +<pre class="brush:js ">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]}));</pre> <p>자주 쓰이는 용례에 대해서는 <code>eval()</code>이나 <code>Function()</code>보다 안전하고 빠른 대안도 존재합니다.</p> @@ -141,7 +141,7 @@ return"Monday Tuesday Wednesday Thursday Friday Saturday Sunday".split(" ")[a%7| <p>속성명으로 속성을 찾는 데 <code>eval()</code>을 사용해서는 안 됩니다. 다음 예제와 같이 코드를 실행하기 전까지는 접근할 속성을 알 수 없는 상황을 생각해 봅시다. 이 상황은 <code>eval</code>로 처리할 수 있습니다.</p> -<pre class="brush:js notranslate">var obj = { a: 20, b: 30 }; +<pre class="brush:js ">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 ); <p>그러나 여기에서 <code>eval()</code>을 쓸 필요가 없고, 지양되어야 합니다. 그 대신 훨씬 빠르고 안전한 <a href="/ko/docs/Web/JavaScript/Reference/Operators/Property_Accessors">속성 접근자</a>를 사용하여야 합니다.</p> -<pre class="brush:js notranslate">var obj = { a: 20, b: 30 }; +<pre class="brush:js ">var obj = { a: 20, b: 30 }; var propname = getPropName(); // "a" 또는 "b"를 반환 var result = obj[ propname ]; // obj[ "a" ]는 obj.a와 동일함 </pre> <p>이 방법으로 더 깊은 속성에도 접근할 수 있습니다. <code>eval()</code>을 사용한다면 다음과 같을 것입니다.</p> -<pre class="notranslate"><code>var obj = {a: {b: {c: 0}}}; +<pre ><code>var obj = {a: {b: {c: 0}}}; var propPath = getPropPath(); // "a.b.c"를 반환한다고 가정 eval( 'var result = obj.' + propPath );</code></pre> <p>여기서 <code>eval()</code>의 사용을 피하려면 속성 경로를 <code><a href="/ko/docs/Web/JavaScript/Reference/Global_Objects/String/split">split</a></code>한 다음 순서대로 접근할 수도 있습니다.</p> -<pre class="notranslate"><code>function getDescendantProp(obj, desc) { +<pre ><code>function getDescendantProp(obj, desc) { var arr = desc.split('.'); while (arr.length) { obj = obj[arr.shift()]; @@ -177,7 +177,7 @@ var result = getDescendantProp(obj, propPath);</code></pre> <p>속성에 값을 대입하는 것도 비슷하게 할 수 있습니다.</p> -<pre class="notranslate"><code>function setDescendantProp(obj, desc, value) { +<pre ><code>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로 <p>JavaScript의 <a href="http://en.wikipedia.org/wiki/First-class_function">함수는 1급 객체</a>이므로 다른 API에 함수를 인자로 전달할 수도 있고, 변수나 객체의 속성으로 대입할 수도 있습니다. 다수의 DOM API는 이 점을 염두에 두고 설계되므로, 다음과 같이 코드를 짜야 합니다.</p> -<pre class="brush: js notranslate">// setTimeout(" ... ", 1000) 대신에 +<pre class="brush: js ">// setTimeout(" ... ", 1000) 대신에 setTimeout(function() { ... }, 1000); // elt.setAttribute("onclick", "...") 대신에 @@ -222,7 +222,7 @@ elt.addEventListener("click", function() { ... } , false); </pre> <p>아래 코드에서 <code>eval()</code>를 포함하는 문장은 모두 42를 반환합니다. 전자는 문자열 "<code>x + y + 1</code>"을, 후자는 문자열 "<code>42</code>"를 평가합니다.</p> -<pre class="brush:js notranslate">var x = 2; +<pre class="brush:js ">var x = 2; var y = 39; var z = "42"; eval("x + y + 1"); // 42를 반환 @@ -233,14 +233,14 @@ eval(z); // 42를 반환 <p>다음 예제에서는 <code>eval()</code>을 사용하여 <code>str</code> 문자열을 평가합니다. 이 문자열은 <code>x</code>가 5이면 로그를 출력한 다음 <code>z</code>에 42를 할당하고, 그렇지 않으면 <code>z</code>에 0 을 할당하는 JavaScript 코드입니다. 두 번째 문장이 실행되면, <code>eval()</code>은 이 문장의 집합을 수행하고, <code>z</code>에 할당된 값을 반환합니다.</p> -<pre class="brush:js notranslate">var x = 5; +<pre class="brush:js ">var x = 5; var str = "if (x == 5) {console.log('z is 42'); z = 42;} else z = 0; "; console.log("z is ", eval(str));</pre> <p>여러 값을 정의할 경우 마지막 값을 반환합니다.</p> -<pre class="notranslate"><code>var x = 5; +<pre ><code>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</code></pre> @@ -249,7 +249,7 @@ console.log('x is ', eval(str)); // z는 42, x는 420</code></pre> <p><code>eval()</code> 은 마지막 표현식의 평가값을 반환합니다.</p> -<pre class="brush:js notranslate">var str = "if ( a ) { 1+1; } else { 1+2; }"; +<pre class="brush:js ">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);</pre> <h3 id="함수_정의_문자열로서의_eval_은_앞뒤를_와_로_감싸야_한다">함수 정의 문자열로서의 <code>eval</code> 은 앞뒤를 "("와 ")"로 감싸야 한다</h3> -<pre class="brush:js notranslate">var fctStr1 = "function a() {}" +<pre class="brush:js ">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 <p><code>globalThis</code> 없이 현재 환경의 전역 객체를 가져오는 방법 중 유일하게 믿을만한 방법은 <code>Function('return this')()</code> 입니다. 그러나 일부 환경에서는 <a href="/ko/docs/Web/HTTP/CSP">CSP</a> 위반에 걸리는 코드이므로, <a href="https://github.com/paulmillr/es6-shim">es6-shim</a>은 대신 다음 검사를 수행합니다.</p> -<pre class="brush: js notranslate">var getGlobal = function () { +<pre class="brush: js ">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') { <p><code>globalThis</code>를 사용할 수 있으면 환경별 전역 객체 검사는 더 이상 필요하지 않습니다.</p> -<pre class="brush: js notranslate">if (typeof globalThis.setTimeout !== 'function') { +<pre class="brush: js ">if (typeof globalThis.setTimeout !== 'function') { // no setTimeout in this environment! }</pre> 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 <h2 id="예제">예제</h2> -<pre class="brush: js notranslate">console.log(Infinity); /* Infinity */ +<pre class="brush: js ">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 <p><code>NaN</code>은 다른 모든 값과 비교(<code>==</code>, <code>!=</code>, <code>===</code>, <code>!==</code>)했을 때 같지 않으며, 다른 NaN과도 같지 않습니다. NaN의 판별은 {{jsxref("Number.isNaN()")}} 또는 {{jsxref("Global_Objects/isNaN", "isNaN()")}}을 사용하면 제일 분명하게 수행할 수 있습니다. 아니면, 오로지 NaN만이 자기자신과 비교했을 때 같지 않음을 이용할 수도 있습니다.</p> -<pre class="brush: js notranslate">NaN === NaN; // false +<pre class="brush: js ">NaN === NaN; // false Number.NaN === NaN; // false isNaN(NaN); // true isNaN(Number.NaN); // true @@ -52,13 +52,13 @@ valueIsNaN(Number.NaN); // true <p>그러나 <code>isNaN()</code>과 <code>Number.isNaN()</code>의 차이를 주의해야 합니다. <code>isNaN</code>은 현재 값이 <code>NaN</code>이거나, 숫자로 변환했을 때 <code>NaN</code>이 되면 참을 반환하지만, <code>Number.isNaN</code>은 현재 값이 <code>NaN</code>이어야만 참을 반환합니다.</p> -<pre class="brush: js notranslate">isNaN('hello world'); // true +<pre class="brush: js ">isNaN('hello world'); // true Number.isNaN('hello world'); // false </pre> <p>덧붙여서, 일부 배열 메서드는 NaN을 찾을 수 없습니다.</p> -<pre class="brush: js notranslate">let arr = [2, 4, NaN, 12]; +<pre class="brush: js ">let arr = [2, 4, NaN, 12]; arr.indexOf(NaN); // -1 (false) arr.includes(NaN); // true arr.findIndex(n => Number.isNaN(n)); // 2</pre> 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 <p>다음 코드에서 <code>smallNumber</code>는 JavaScript의 최솟값보다 작은 값을 할당받습니다. {{jsxref("Statements/if...else", "if")}} 문이 실행되면, <code>smallNumber</code>의 값이 <code>-Infinity</code>이므로 <code>smallNumber</code>는 계산에 좀 더 적합한 값을 다시 할당합니다.</p> -<pre class="brush: js notranslate">var smallNumber = (-Number.MAX_VALUE) * 2; +<pre class="brush: js ">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 <h2 id="Syntax">Syntax</h2> -<pre class="syntaxbox notranslate">Object.entries(<var>obj</var>)</pre> +<pre class="syntaxbox ">Object.entries(<var>obj</var>)</pre> <h3 id="Parameters">Parameters</h3> @@ -36,7 +36,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/entries <p>기본적으로 지원하지 않는 이전 환경에서 호환 가능한 <code>Object.entries</code> 지원을 추가하려면 <a href="https://github.com/tc39/proposal-object-values-entries">tc39/proposal-object-values-entries</a>에 Object.entries의 데모 구현을 찾을 수 있습니다 (IE에 대한 지원이 필요하지 않은 경우) , <a href="https://github.com/es-shims/Object.entries">es-shims/Object.entries</a> 저장소에있는 polyfill을 사용하거나 아래에 나열된 polyfill을 간단하게 배치 할 수 있습니다.</p> -<pre class="brush: js notranslate">if (!Object.entries) +<pre class="brush: js ">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 <h2 id="Examples">Examples</h2> -<pre class="brush: js notranslate">const obj = { foo: 'bar', baz: 42 }; +<pre class="brush: js ">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" -<pre class="brush: js notranslate">const obj = { foo: 'bar', baz: 42 }; +<pre class="brush: js ">const obj = { foo: 'bar', baz: 42 }; const map = new Map(Object.entries(obj)); console.log(map); // Map { foo: "bar", baz: 42 } </pre> @@ -103,7 +103,7 @@ console.log(map); // Map { foo: "bar", baz: 42 } <p><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Array_destructuring">Array Destructuring</a>을 사용하면 객체를 쉽게 반복 할 수 있습니다.</p> -<pre class="brush: js notranslate">const obj = { foo: 'bar', baz: 42 }; +<pre class="brush: js ">const obj = { foo: 'bar', baz: 42 }; Object.entries(obj).forEach(([key, value]) => console.log(`${key}: ${value}`)); // "foo: bar", "baz: 42" </pre> 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 <h2 id="Syntax">Syntax</h2> -<pre class="syntaxbox notranslate"><code>Object.setPrototypeOf(<var>obj</var>, <var>prototype</var>);</code></pre> +<pre class="syntaxbox "><code>Object.setPrototypeOf(<var>obj</var>, <var>prototype</var>);</code></pre> <h3 id="Parameters">Parameters</h3> @@ -37,14 +37,14 @@ browser-compat: javascript.builtins.Object.setPrototypeOf <p>Examples</p> -<pre class="brush: js notranslate">var dict = Object.setPrototypeOf({}, null); +<pre class="brush: js ">var dict = Object.setPrototypeOf({}, null); </pre> <h2 id="Polyfill">Polyfill</h2> <p>예전 버전의 프로퍼티 {{jsxref("Object.prototype.__proto__")}} 를 사용한다면, 우리는 쉽게 Object.setPrototypeOf 가 쉽게 정의 할수 있다.</p> -<pre class="brush: js notranslate">// Only works in Chrome and FireFox, does not work in IE: +<pre class="brush: js ">// 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) { <p><code>Object.getPrototypeOf()</code> and {{jsxref("Object.proto", "Object.prototype.__proto__")}} 의 결합은 새로운 프로토타입 오브젝트에 전반적인 프로토타입 Chain을 설정하도록 할수 있다.</p> -<pre class="brush: js notranslate">/** +<pre class="brush: js ">/** *** 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) { <h4 id="First_example_프로토타입에_Chain_설정하기">First example: 프로토타입에 Chain 설정하기</h4> -<pre class="brush: js notranslate">function Mammal() { +<pre class="brush: js ">function Mammal() { this.isMammal = 'yes'; } @@ -129,7 +129,7 @@ console.log(oCat.breathing); // 'yes' <h4 id="Second_example_객체_Constructor의_인스턴스에_존재하는_원래_값을_변경_및_해당_객체_프로토타입에_Chain_설정하기">Second example: 객체 Constructor의 인스턴스에 존재하는 원래 값을 변경 및 해당 객체 프로토타입에 Chain 설정하기</h4> -<pre class="brush: js notranslate">function MySymbol() { +<pre class="brush: js ">function MySymbol() { this.isSymbol = 'yes'; } @@ -146,7 +146,7 @@ console.log(typeof oPrime); // 'object' <h4 id="Third_example_Function.prototype객체에_Chain을_설정하고_그_Chain에_새로운_함수를_설정하기">Third example: Function.prototype객체에 Chain을 설정하고 그 Chain에 새로운 함수를 설정하기</h4> -<pre class="brush: js notranslate">function Person(sName) { +<pre class="brush: js ">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 <h2 id="구문">구문</h2> -<pre class="syntaxbox notranslate"><var>regexObj</var>.exec(<var>str</var>)</pre> +<pre class="syntaxbox "><var>regexObj</var>.exec(<var>str</var>)</pre> <h3 id="매개변수">매개변수</h3> @@ -45,7 +45,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/exec <p>다음과 같은 예제를 고려해보세요.</p> -<pre class="brush: js notranslate">// Match "quick brown" followed by "jumps", ignoring characters in between +<pre class="brush: js ">// 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');</pre> <p>If your regular expression uses the "<code>g</code>" flag, you can use the <code>exec()</code> method multiple times to find successive matches in the same string. When you do so, the search starts at the substring of <code>str</code> 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:</p> -<pre class="brush: js notranslate">var myRe = /ab*/g; +<pre class="brush: js ">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) { <p>This script displays the following text:</p> -<pre class="notranslate">Found abb. Next match starts at 3 +<pre >Found abb. Next match starts at 3 Found ab. Next match starts at 9 </pre> @@ -153,7 +153,7 @@ Found ab. Next match starts at 9 <p>You can also use <code>exec()</code> without creating a {{jsxref("RegExp")}} object:</p> -<pre class="brush: js notranslate">var matches = /(hello \S+)/.exec('This is a hello world!'); +<pre class="brush: js ">var matches = /(hello \S+)/.exec('This is a hello world!'); console.log(matches[1]); </pre> 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 <p>다음의 세 표현식은 모두 같은 정규 표현식을 생성합니다.</p> -<pre class="brush: js notranslate">/ab+c/i +<pre class="brush: js ">/ab+c/i new RegExp(/ab+c/, 'i') // 리터럴 new RegExp('ab+c', 'i') // 생성자 </pre> @@ -46,7 +46,7 @@ new RegExp('ab+c', 'i') // 생성자 <p>예를 들어 다음 두 줄은 동일한 정규 표현식을 생성합니다.</p> -<pre class="brush: js notranslate">let re = /\w+/ +<pre class="brush: js ">let re = /\w+/ let re = new RegExp('\\w+')</pre> <h3 id="Perl_형태의_RegExp_속성">Perl 형태의 <code>RegExp</code> 속성</h3> @@ -121,7 +121,7 @@ let re = new RegExp('\\w+')</pre> <p>대치 문자열에는 <code>$1</code>과 <code>$2</code>를 사용하여 정규 표현식 패턴의 각 괄호에 일치한 결과를 받아옵니다.</p> -<pre class="brush: js notranslate">let re = /(\w+)\s(\w+)/ +<pre class="brush: js ">let re = /(\w+)\s(\w+)/ let str = 'John Smith' let newstr = str.replace(re, '$2, $1') console.log(newstr)</pre> @@ -132,7 +132,7 @@ console.log(newstr)</pre> <p>기본 줄 바꿈 문자는 플랫폼(Unix, Windows 등)마다 다릅니다. 아래의 분할 스크립트는 모든 플랫폼의 줄 바꿈을 인식합니다.</p> -<pre class="brush: js notranslate">let text = 'Some text\nAnd some more\r\nAnd yet\rThis is the end' +<pre class="brush: js ">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' ]</pre> @@ -140,7 +140,7 @@ console.log(lines) // logs [ 'Some text', 'And some more', 'And yet', 'This is t <h3 id="여러_줄에서_정규_표현식_사용하기">여러 줄에서 정규 표현식 사용하기</h3> -<pre class="brush: js notranslate">let s = 'Please yes\nmake my day!' +<pre class="brush: js ">let s = 'Please yes\nmake my day!' s.match(/yes.*day/); // Returns null @@ -152,7 +152,7 @@ s.match(/yes[^]*day/); <p>{{JSxRef("Global_Objects/RegExp/sticky", "sticky")}} 플래그는 해당 정규 표현식이 접착 판별, 즉 {{jsxref("RegExp.prototype.lastIndex")}}에서 시작하는 일치만 확인하도록 할 수 있습니다.</p> -<pre class="brush: js notranslate">let str = '#foo#' +<pre class="brush: js ">let str = '#foo#' let regex = /foo/y regex.lastIndex = 1 @@ -165,7 +165,7 @@ regex.lastIndex // 0 (reset after match failure)</pre> <p>접착 플래그 <code>y</code>의 일치는 정확히 <code>lastIndex</code> 위치에서만 발생할 수 있으나, 전역 플래그 <code>g</code>의 경우 <code>lastIndex</code> 또는 그 이후에서도 발생할 수 있습니다.</p> -<pre class="brush: js notranslate">re = /\d/y; +<pre class="brush: js ">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); <p>러시아어나 히브리어와 같은 다른 언어의 문자까지 일치하려면 <code>\uhhhh</code>(이때 hhhh는 해당 문자의 16진법 Unicode 값) 문법을 사용하세요. 아래 예제에서는 문자열에서 Unicode 문자를 추출합니다.</p> -<pre class="brush: js notranslate">let text = 'Образец text на русском языке' +<pre class="brush: js ">let text = 'Образец text на русском языке' let regex = /[\u0400-\u04FF]+/g let match = regex.exec(text) @@ -198,7 +198,7 @@ console.log(regex.lastIndex) // logs '15' <h3 id="URL에서_서브도메인_추출하기">URL에서 서브도메인 추출하기</h3> -<pre class="brush: js notranslate">let url = 'http://xxx.domain.com' +<pre class="brush: js ">let url = 'http://xxx.domain.com' console.log(/[^.]+/.exec(url)[0].substr(7)) // logs 'xxx'</pre> <div class="blockIndicator note"> 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 <p>리터럴, 생성자, 팩토리 표기법이 가능합니다.</p> -<pre class="syntaxbox notranslate">/<var>pattern</var>/<var>flags</var> +<pre class="syntaxbox ">/<var>pattern</var>/<var>flags</var> new RegExp(<var>pattern</var>[, <var>flags</var>]) RegExp(<var>pattern</var>[, <var>flags</var>]) </pre> @@ -73,7 +73,7 @@ RegExp(<var>pattern</var>[, <var>flags</var>]) <p>다음의 세 표현식은 모두 같은 정규 표현식을 생성합니다.</p> -<pre class="brush: js notranslate">/ab+c/i +<pre class="brush: js ">/ab+c/i new RegExp(/ab+c/, 'i') // 리터럴 new RegExp('ab+c', 'i') // 생성자 </pre> 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 <h2 id="구문">구문</h2> -<pre class="syntaxbox notranslate"><var>regexObj</var>.test(<var>str</var>)</pre> +<pre class="syntaxbox "><var>regexObj</var>.test(<var>str</var>)</pre> <h3 id="매개변수">매개변수</h3> @@ -48,7 +48,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/test <p>문자열의 맨 처음에 <code>"hello"</code>가 포함됐는지 알아보는 간단한 예제 코드입니다.</p> -<pre class="brush: js notranslate">const str = 'hello world!'; +<pre class="brush: js ">const str = 'hello world!'; const result = /^hello/.test(str); console.log(result); // true @@ -56,7 +56,7 @@ console.log(result); // true <p>다음은 일치 여부에 따라 다른 메시지를 기록하는 예제입니다.</p> -<pre class="brush: js notranslate">function testInput(re, str) { +<pre class="brush: js ">function testInput(re, str) { let midstring; if (re.test(str)) { midstring = 'contains'; @@ -81,7 +81,7 @@ console.log(result); // true <p>이 행동에 대한 예제가 다음 코드입니다.</p> -<pre class="brush: js notranslate">const regex = /foo/g; // the "global" flag is set +<pre class="brush: js ">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 <h2 id="구문">구문</h2> -<pre class="syntaxbox notranslate"><var>str</var>.lastIndexOf(<var>searchValue</var>[, <var>fromIndex</var>])</pre> +<pre class="syntaxbox "><var>str</var>.lastIndexOf(<var>searchValue</var>[, <var>fromIndex</var>])</pre> <h3 id="매개변수">매개변수</h3> @@ -38,7 +38,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/lastIndexOf <p>문자열의 문자는 왼쪽에서 오른쪽으로 인덱스를 매깁니다. 첫 번째 문자의 인덱스는 <code>0</code>이며, 마지막 문자의 인덱스는 <code>str.length -1</code>입니다.</p> -<pre class="brush: js notranslate">'canal'.lastIndexOf('a'); // 3 반환 +<pre class="brush: js ">'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 <p><code>lastIndexOf()</code> 메서드는 대소문자를 구분합니다. 예를 들어, 아래 예제는 <code>-1</code>을 반환합니다.</p> -<pre class="brush: js notranslate">'Blue Whale, Killer Whale'.lastIndexOf('blue'); // -1 반환 +<pre class="brush: js ">'Blue Whale, Killer Whale'.lastIndexOf('blue'); // -1 반환 </pre> <h2 id="예제">예제</h2> @@ -65,7 +65,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/lastIndexOf <p>아래 예제는 문자열 <code>"Brave new world"</code> 내에서 특정 값의 위치를 확인하기 위해 {{jsxref("String.prototype.indexOf()", "indexOf()")}}와 <code>lastIndexOf()</code>를 사용합니다.</p> -<pre class="brush: js notranslate">let anyString = 'Brave new world'; +<pre class="brush: js ">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 <h2 id="문법">문법</h2> -<pre class="syntaxbox notranslate"><code><var>str</var>.slice(<var>beginIndex</var>[, <var>endIndex</var>])</code></pre> +<pre class="syntaxbox "><code><var>str</var>.slice(<var>beginIndex</var>[, <var>endIndex</var>])</code></pre> <h3 id="매개변수">매개변수</h3> @@ -47,7 +47,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/slice <p>아래 예시는 새 문자열을 생성하기 위해 <code>slice()</code>를 사용합니다.</p> -<pre class="brush: js notranslate">var str1 = 'The morning is upon us.', // the length of str1 is 23. +<pre class="brush: js ">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: "" <p>아래 예시는 <code>slice()</code>에 음수 인덱스를 사용합니다.</p> -<pre class="brush: js notranslate">var str = 'The morning is upon us.'; +<pre class="brush: js ">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' <p>아래의 예시는 시작 인덱스를 찾기 위해 문자열의 끝에서부터 역방향으로 <code>11</code>개를 세고 끝 인덱스를 찾기 위해 문자열의 시작에서부터 정방향으로 <code>16</code>개를 셉니다.</p> -<pre class="brush: js notranslate"><code>console.log(str.slice(-11, 16)) // => "is u";</code></pre> +<pre class="brush: js "><code>console.log(str.slice(-11, 16)) // => "is u";</code></pre> <p>아래에서는 시작 인덱스를 찾기 위해 문자열의 처음부터 정방향으로 <code>11</code>개를 세고 끝 인덱스를 찾기 위해 끝에서부터 <code>7</code>개를 셉니다.</p> -<pre class="brush: js notranslate"><code>console.log(str.slice(11, -7)) // => "is u";</code> +<pre class="brush: js "><code>console.log(str.slice(11, -7)) // => "is u";</code> </pre> <p>이 인수는 끝에서부터 5로 역순으로 계산하여 시작 인덱스를 찾은 다음 끝에서부터 1을 거쳐 끝 인덱스를 찾습니다.</p> -<pre class="brush: js notranslate"><code>console.log(str.slice(-5, -1)) // => "n us";</code> +<pre class="brush: js "><code>console.log(str.slice(-5, -1)) // => "n us";</code> </pre> <h2 id="Specifications">Specifications</h2> 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 <h2 id="구문">구문</h2> -<pre class="syntaxbox notranslate">undefined</pre> +<pre class="syntaxbox ">undefined</pre> <h2 id="설명">설명</h2> @@ -29,7 +29,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/undefined <div class="note"> <p><code>undefined</code>는 <a href="/ko/docs/Web/JavaScript/Reference/Reserved_Words">예약어</a>가 아니기 때문에 전역 범위 외에서 {{Glossary("Identifier", "식별자")}}(변수 이름)로 사용할 수 있습니다. 그러나 유지보수와 디버깅 시 어려움을 낳을 수 있으므로 반드시 피해야 합니다.</p> -<pre class="brush: js example-bad notranslate">// DON'T DO THIS +<pre class="brush: js example-bad ">// DON'T DO THIS // logs "foo string" (function() { @@ -49,7 +49,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/undefined <p><code>undefined</code>와 일치, 불일치 연산자를 사용해 변수에 값이 할당됐는지 판별할 수 있습니다. 다음 예제에서 변수 <code>x</code>는 초기화되지 않았으므로 <code>if</code>문은 <code>true</code>로 평가됩니다.</p> -<pre class="brush: js notranslate">var x; +<pre class="brush: js ">var x; if (x === undefined) { // 이 문이 실행됨 } @@ -68,7 +68,7 @@ else { <p>위의 예제 대신 {{jsxref("Operators/typeof", "typeof")}}를 사용할 수도 있습니다.</p> -<pre class="brush: js notranslate">var x; +<pre class="brush: js ">var x; if (typeof x === 'undefined') { // 이 문이 실행됨 } @@ -76,7 +76,7 @@ if (typeof x === 'undefined') { <p><code>typeof</code>를 사용하는 이유 중 하나는 선언하지 않은 변수를 사용해도 오류를 던지지 않기 때문입니다.</p> -<pre class="brush: js notranslate">// x를 선언한 적 없음 +<pre class="brush: js ">// x를 선언한 적 없음 if (typeof x === 'undefined') { // 오류 없이 true로 평가 // 이 문이 실행됨 } @@ -90,7 +90,7 @@ if(x === undefined) { // ReferenceError <p>전역 범위는 {{jsxref("globalThis", "전역 객체", "", 1)}}에 묶여 있으므로, 전역 맥락에서 변수의 존재 유무는 {{jsxref("Operators/in", "in")}} 연산자를 전역 객체 대상으로 실행해 알 수 있습니다. 즉,</p> -<pre class="brush: js notranslate">if ('x' in window) { +<pre class="brush: js ">if ('x' in window) { // x가 전역으로 정의된 경우 이 문이 실행됨 }</pre> @@ -98,7 +98,7 @@ if(x === undefined) { // ReferenceError <p>{{jsxref("Operators/void", "void")}} 연산자를 제 3의 대안으로 사용할 수 있습니다.</p> -<pre class="brush: js notranslate">var x; +<pre class="brush: js ">var x; if (x === void 0) { // 이 문이 실행됨 } |