Thanks to visit codestin.com
Credit goes to github.com

Skip to content

#359 [함수의 prototype 프로퍼티] 과제1 정답 번역 #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
`"constructor"` ������Ƽ�� ����� �� ���� ����Ǿ��ִٸ� ���� ���� ���ٹ��� �����մϴ�.

Answers:
�⺻ `"prototype"`�� �������� �ʾҴٸ� �Ʒ� ���ô� �ǵ��� ��� �����մϴ�.

1. `true`.
```js run
function User(name) {
this.name = name;
};

The assignment to `Rabbit.prototype` sets up `[[Prototype]]` for new objects, but it does not affect the existing ones.
let user = new User('John');
let user2 = new user.constructor('Pete');

2. `false`.
alert( user2.name ); // Pete (�� �����ϳ׿�!)
```

Objects are assigned by reference. The object from `Rabbit.prototype` is not duplicated, it's still a single object referenced both by `Rabbit.prototype` and by the `[[Prototype]]` of `rabbit`.
`User.prototype.constructor == User`�̱� ������ �� ���ô� ����� �����մϴ�.

So when we change its content through one reference, it is visible through the other one.
�׷��� �������� `User.prototype`�� ����� `User`�� �����ϴ� `constructor`�� �ٽ� ������ִ� �� �ؾ��ٸ� ������ ���ٹ��� �����մϴ�.

3. `true`.
����:

All `delete` operations are applied directly to the object. Here `delete rabbit.eats` tries to remove `eats` property from `rabbit`, but it doesn't have it. So the operation won't have any effect.
```js run
function User(name) {
this.name = name;
};
*!*
User.prototype = {}; // (*)
*/!*

4. `undefined`.
let user = new User('John');
let user2 = new user.constructor('Pete');

The property `eats` is deleted from the prototype, it doesn't exist any more.
alert( user2.name ); // undefined
```

�� `user2.name`�� `undefined`�� �ɱ��?

�� ������ `new user.constructor('Pete')`�� �Ʒ��� ���� �����ϱ� �����Դϴ�.

1. `new user.constructor('Pete')`�� `user`���� `constructor`�� ã�µ� �ƹ��͵� ã�� ���մϴ�.
2. ��ü���� ���ϴ� ������Ƽ�� ã�� ���߱� ������ ������Ÿ�Կ��� �˻��� �����մϴ�. `user`�� ������Ÿ���� `User.prototype`�ε�, `User.prototype`�� �� ��ü�Դϴ�.
3. `User.prototype`�� �Ϲ� ��ü `{}`�̰�, �Ϲ� ��ü�� ������Ÿ���� `Object.prototype`�Դϴ�. `Object.prototype.constructor == Object`�̹Ƿ� `Object`�� ���˴ϴ�.

�ᱹ�� `let user2 = new user.constructor('Pete');`�� `let user2 = new Object('Pete')`�� �˴ϴ�. �׷��� `Object`�� �����ڴ� �μ��� �����ϰ� �׻� �� ��ü�� �����մϴ�. ���� `let user2 = new Object('Pete')`�� `let user2 = {}`�� ���ٰ� ������ �� �ֽ��ϴ�. `user2.name`�� `undefined`�� ������ ���⿡ �ֽ��ϴ�.