Skip to content

Commit cc9385a

Browse files
committed
[객체와 메서드, this] 충돌 해결 (본문)
1 parent 71ab899 commit cc9385a

1 file changed

Lines changed: 0 additions & 31 deletions

File tree

1-js/04-object-basics/04-object-methods/article.md

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,11 @@ user.sayHi = function() {
3232
user.sayHi(); // 안녕하세요!
3333
```
3434

35-
<<<<<<< HEAD
3635
함수 표현식으로 함수를 만들고, 객체 프로퍼티 `user.sayHi`에 함수를 할당해 주었습니다.
3736

3837
이제 객체에 할당된 함수를 호출하면 user가 인사를 해줍니다.
3938

4039
이렇게 객체 프로퍼티에 할당된 함수를 *메서드(method)* 라고 부릅니다.
41-
=======
42-
Here we've just used a Function Expression to create a function and assign it to the property `user.sayHi` of the object.
43-
44-
Then we can call it as `user.sayHi()`. The user can now speak!
45-
46-
A function that is a property of an object is called its *method*.
47-
>>>>>>> upstream/master
4840

4941
위 예시에선 `user`에 할당된 `sayHi`가 메서드이죠.
5042

@@ -58,13 +50,8 @@ let user = {
5850
*!*
5951
// 함수 선언
6052
function sayHi() {
61-
<<<<<<< HEAD
6253
alert("안녕하세요!");
6354
};
64-
=======
65-
alert("Hello!");
66-
}
67-
>>>>>>> upstream/master
6855

6956
// 선언된 함수를 메서드로 등록
7057
user.sayHi = sayHi;
@@ -94,11 +81,7 @@ user = {
9481
// 단축 구문을 사용하니 더 깔끔해 보이네요.
9582
user = {
9683
*!*
97-
<<<<<<< HEAD
9884
sayHi() { // "sayHi: function()"과 동일합니다.
99-
=======
100-
sayHi() { // same as "sayHi: function(){...}"
101-
>>>>>>> upstream/master
10285
*/!*
10386
alert("Hello");
10487
}
@@ -107,11 +90,7 @@ user = {
10790

10891
위처럼 `function`을 생략해도 메서드를 정의할 수 있습니다.
10992

110-
<<<<<<< HEAD
11193
일반적인 방법과 단축 구문을 사용한 방법이 완전히 동일하진 않습니다. 객체 상속과 관련된 미묘한 차이가 존재하는데 지금으로선 이 차이가 중요하지 않기 때문에 넘어가도록 하겠습니다.
112-
=======
113-
To tell the truth, the notations are not fully identical. There are subtle differences related to object inheritance (to be covered later), but for now they do not matter. In almost all cases, the shorter syntax is preferred.
114-
>>>>>>> upstream/master
11594

11695
## 메서드와 this
11796

@@ -181,24 +160,14 @@ let user = {
181160
let admin = user;
182161
user = null; // user를 null로 덮어씁니다.
183162

184-
<<<<<<< HEAD
185163
admin.sayHi(); // sayHi()가 엉뚱한 객체를 참고하면서 에러가 발생했습니다.
186-
=======
187-
*!*
188-
admin.sayHi(); // TypeError: Cannot read property 'name' of null
189-
*/!*
190-
>>>>>>> upstream/master
191164
```
192165

193166
`alert` 함수가 `user.name` 대신 `this.name`을 인수로 받았다면 에러가 발생하지 않았을 겁니다.
194167

195168
## 자유로운 this
196169

197-
<<<<<<< HEAD
198170
자바스크립트의 `this`는 다른 프로그래밍 언어의 `this`와 동작 방식이 다릅니다. 자바스크립트에선 모든 함수에 `this`를 사용할 수 있습니다.
199-
=======
200-
In JavaScript, keyword `this` behaves unlike most other programming languages. It can be used in any function, even if it's not a method of an object.
201-
>>>>>>> upstream/master
202171

203172
아래와 같이 코드를 작성해도 문법 에러가 발생하지 않습니다.
204173

0 commit comments

Comments
 (0)