Skip to content

Commit

Permalink
ko: Format /web/javascript using Prettier (part 3) (#14822)
Browse files Browse the repository at this point in the history
  • Loading branch information
queengooborg committed Aug 8, 2023
1 parent 84b2b6d commit 4e5ab42
Show file tree
Hide file tree
Showing 100 changed files with 1,226 additions and 1,046 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: EvalError
slug: Web/JavaScript/Reference/Global_Objects/EvalError
---

{{JSRef}}

**`EvalError`** 객체는 전역 {{jsxref("Global_Objects/eval", "eval()")}} 함수에 관한 오류를 나타냅니다. 이 예외는 JavaScript에 의해 더 이상 발생하지 않지만 `EvalError` 객체는 하위 호환성을 위해 남아있습니다.
Expand Down Expand Up @@ -34,15 +35,15 @@ slug: Web/JavaScript/Reference/Global_Objects/EvalError

```js
try {
throw new EvalError('Hello', 'someFile.js', 10);
throw new EvalError("Hello", "someFile.js", 10);
} catch (e) {
console.log(e instanceof EvalError); // true
console.log(e.message); // "Hello"
console.log(e.name); // "EvalError"
console.log(e.fileName); // "someFile.js"
console.log(e.lineNumber); // 10
console.log(e.columnNumber); // 0
console.log(e.stack); // "@Scratchpad/2:2:9\n"
console.log(e.message); // "Hello"
console.log(e.name); // "EvalError"
console.log(e.fileName); // "someFile.js"
console.log(e.lineNumber); // 10
console.log(e.columnNumber); // 0
console.log(e.stack); // "@Scratchpad/2:2:9\n"
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ slug: Web/JavaScript/Reference/Global_Objects/Function/apply
## 구문

```js
func.apply(thisArg, [argsArray])
func.apply(thisArg, [argsArray]);
```

### 매개변수
Expand Down Expand Up @@ -49,7 +49,7 @@ ECMAScript 5번 째 판의 시작으로, 모든 유사 배열 객체 타입을
방법은 `apply` !

```js
var array = ['a', 'b'];
var array = ["a", "b"];
var elements = [0, 1, 2];
array.push.apply(array, elements);
console.info(array); // ["a", "b", 0, 1, 2]
Expand All @@ -71,7 +71,7 @@ var max = Math.max.apply(null, numbers);
var min = Math.min.apply(null, numbers);

// vs. simple loop based algorithm
max = -Infinity, min = +Infinity;
(max = -Infinity), (min = +Infinity);

for (var i = 0; i < numbers.length; i++) {
if (numbers[i] > max) {
Expand All @@ -93,8 +93,7 @@ function minOfArray(arr) {
var QUANTUM = 32768;

for (var i = 0, len = arr.length; i < len; i += QUANTUM) {
var submin = Math.min.apply(null,
arr.slice(i, Math.min(i + QUANTUM, len)));
var submin = Math.min.apply(null, arr.slice(i, Math.min(i + QUANTUM, len)));
min = Math.min(submin, min);
}

Expand All @@ -109,7 +108,7 @@ var min = minOfArray([5, 6, 2, 3, 7]);
Java 와 유사하게, 객체를 위한 {{jsxref("Operators/new", "constructors", "", 1)}} 체이닝을 위해 `apply` 를 사용할 수 있습니다. 다음 예제에서 인수 리스트 대신 생성자로 유사 배열 객체를 사용할 수 있게 해주는 `construct` 라는 전역 {{jsxref("Function")}} 메소드를 생성할 것입니다.

```js
Function.prototype.construct = function(aArgs) {
Function.prototype.construct = function (aArgs) {
var oNew = Object.create(this.prototype);
this.apply(oNew, aArgs);
return oNew;
Expand All @@ -126,7 +125,7 @@ Function.prototype.construct = function (aArgs) {
oNew.__proto__ = this.prototype;
this.apply(oNew, aArgs);
return oNew;
};
};
```

[클로져](/ko/docs/Web/JavaScript/Guide/Closures) 사용:
Expand Down Expand Up @@ -156,18 +155,18 @@ Function.prototype.construct = function (aArgs) {
사용 예제

```js
function MyConstructor() {
for (var nProp = 0; nProp < arguments.length; nProp++) {
this['property' + nProp] = arguments[nProp];
}
}

var myArray = [4, 'Hello world!', false];
var myInstance = MyConstructor.construct(myArray);

console.log(myInstance.property1); // logs 'Hello world!'
console.log(myInstance instanceof MyConstructor); // logs 'true'
console.log(myInstance.constructor); // logs 'MyConstructor'
function MyConstructor() {
for (var nProp = 0; nProp < arguments.length; nProp++) {
this["property" + nProp] = arguments[nProp];
}
}

var myArray = [4, "Hello world!", false];
var myInstance = MyConstructor.construct(myArray);

console.log(myInstance.property1); // logs 'Hello world!'
console.log(myInstance instanceof MyConstructor); // logs 'true'
console.log(myInstance.constructor); // logs 'MyConstructor'
```

**알림:** 네이티브가 아닌 `Function.construct` 메소드는 {{jsxref("Date")}} 와 같은 일부 네이티브 생성자와 동작하지 않을 것입니다. 그런 경우, {{jsxref("Function.prototype.bind")}} 메소드를 사용해야 합니다. 예를 들어, 다음과 같은 배열이 있다고 할 때, {{jsxref("Global_Objects/Date", "Date")}} 생성자: `[2012, 11, 4]` 와 함께 사용되려면 다음과 같이 작성해야 합니다: `new (Function.prototype.bind.apply(Date, [null].concat([2012, 11, 4])))()`. 이는 가장 좋은 방법이 아니며, 어떤 상용 환경에서도 사용되지 않을 수 있습니다.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: Function.arguments
slug: Web/JavaScript/Reference/Global_Objects/Function/arguments
---

{{JSRef}} {{deprecated_header}}

> **`function.arguments`** 속성은 함수로 부터 넘겨 받은 arguments에 해당하는 배열과 같은 객체이다. 간단하게 {{jsxref("Functions/arguments", "arguments")}}를 대신 사용하자. 이 속성은 strict mode에서 [꼬리 호출 최적화](http://www.ecma-international.org/ecma-262/6.0/#sec-addrestrictedfunctionproperties) 때문에 금지 된다.
Expand All @@ -19,17 +20,21 @@ arguments의 값은 함수 실행 과정에서 특별한 호출이 없다면 일
### arguments object를 사용한 예시

```js
function f(n) { g(n - 1); }
function f(n) {
g(n - 1);
}

function g(n) {
console.log('before: ' + g.arguments[0]);
if (n > 0) { f(n); }
console.log('after: ' + g.arguments[0]);
console.log("before: " + g.arguments[0]);
if (n > 0) {
f(n);
}
console.log("after: " + g.arguments[0]);
}

f(2);

console.log('returned: ' + g.arguments);
console.log("returned: " + g.arguments);

// Output

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ slug: Web/JavaScript/Reference/Global_Objects/Function/bind
this.x = 9;
var module = {
x: 81,
getX: function() { return this.x; }
getX: function () {
return this.x;
},
};

module.getX(); // 81
Expand All @@ -72,33 +74,32 @@ boundGetX(); // 81
`bind()`의 다음으로 간단한 사용법은 미리 지정된 초기 인수가 있는 함수를 만드는 겁니다. 지정될 초기 인수가 있다면 제공된 `this` 값을 따르고, 바인딩 된 함수에 전달되어 바인딩 된 함수가 호출될 때마다 대상 함수의 인수 앞에 삽입됩니다.

```js
function list() {
return Array.prototype.slice.call(arguments);
}

var list1 = list(1, 2, 3); // [1, 2, 3]
function list() {
return Array.prototype.slice.call(arguments);
}

// 선행될 인수를 설정하여 함수를 생성합니다.
var leadingThirtysevenList = list.bind(null, 37);
var list1 = list(1, 2, 3); // [1, 2, 3]

var list2 = leadingThirtysevenList(); // [37]
// 선행될 인수를 설정하여 함수를 생성합니다.
var leadingThirtysevenList = list.bind(null, 37);

var list3 = leadingThirtysevenList(1, 2, 3); // [37, 1, 2, 3]
var list2 = leadingThirtysevenList(); // [37]

var list3 = leadingThirtysevenList(1, 2, 3); // [37, 1, 2, 3]

function addArguments(arg1, arg2) {
return arg1 + arg2
}
function addArguments(arg1, arg2) {
return arg1 + arg2;
}

var result1 = addArguments(1, 2); // 3
var result1 = addArguments(1, 2); // 3

// 첫 번째 인수를 지정하여 함수를 생성합니다.
var addThirtySeven = addArguments.bind(null, 37);
// 첫 번째 인수를 지정하여 함수를 생성합니다.
var addThirtySeven = addArguments.bind(null, 37);

var result2 = addThirtySeven(5); // 37 + 5 = 42
var result2 = addThirtySeven(5); // 37 + 5 = 42

// 두 번째 인수는 무시됩니다.
var result3 = addThirtySeven(5, 10); // 37 + 5 = 42
// 두 번째 인수는 무시됩니다.
var result3 = addThirtySeven(5, 10); // 37 + 5 = 42
```

### `setTimeout`과 함께 사용
Expand All @@ -111,13 +112,12 @@ function LateBloomer() {
}

// 1초 지체 후 bloom 선언
LateBloomer.prototype.bloom = function() {
LateBloomer.prototype.bloom = function () {
window.setTimeout(this.declare.bind(this), 1000);
};

LateBloomer.prototype.declare = function() {
console.log('I am a beautiful flower with ' +
this.petalCount + ' petals!');
LateBloomer.prototype.declare = function () {
console.log("I am a beautiful flower with " + this.petalCount + " petals!");
};

var flower = new LateBloomer();
Expand All @@ -137,8 +137,8 @@ function Point(x, y) {
this.y = y;
}

Point.prototype.toString = function() {
return this.x + ',' + this.y;
Point.prototype.toString = function () {
return this.x + "," + this.y;
};

var p = new Point(1, 2);
Expand All @@ -148,11 +148,10 @@ p.toString(); // '1,2'

// 원 bind와는 잘 작동:

var YAxisPoint = Point.bind(null, 0/*x*/);

var YAxisPoint = Point.bind(null, 0 /*x*/);

var emptyObj = {};
var YAxisPoint = Point.bind(emptyObj, 0/*x*/);
var YAxisPoint = Point.bind(emptyObj, 0 /*x*/);

var axisPoint = new YAxisPoint(5);
axisPoint.toString(); // '0,5'
Expand All @@ -172,7 +171,7 @@ new Point(17, 42) instanceof YAxisPoint; // true
// (보통 이를 원하지 않더라도)
YAxisPoint(13);

emptyObj.x + ',' + emptyObj.y;
emptyObj.x + "," + emptyObj.y;
// > '0,13'
```

Expand Down Expand Up @@ -210,22 +209,24 @@ slice(arguments);

```js
if (!Function.prototype.bind) {
Function.prototype.bind = function(oThis) {
if (typeof this !== 'function') {
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") {
// ECMAScript 5 내부 IsCallable 함수와
// 가능한 가장 가까운 것
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
throw new TypeError(
"Function.prototype.bind - what is trying to be bound is not callable",
);
}

var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function() {},
fBound = function() {
return fToBind.apply(this instanceof fNOP
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
return fToBind.apply(
this instanceof fNOP ? this : oThis,
aArgs.concat(Array.prototype.slice.call(arguments)),
);
};

if (this.prototype) {
// Function.prototype은 prototype 속성이 없음
Expand Down
Loading

0 comments on commit 4e5ab42

Please sign in to comment.