코딩공부

[15m] Object literals & Constructors

milimiliemilie 2025. 2. 27. 23:12

# Object literals & Constructors

 

 - Object literals (객체 리터럴): Objects created using object literals are singletons. This means when a change is made to the object, it affects that object across the entire script.

'employee' is also changed to 'Mary'

 

 - Constructors (생성자): Object defined with a function constructor lets you have multiple instances of that object. This means change made to one instance will not affect other instances.

'employee', 'newEmployee'는 서로를 바라보지 않고 각자 'emp'로부터 파생된 것이므로, 사실 둘이 서로에게 영향을 미칠 리가 없긴 하다...

 

# Notes

 - 나는 1번처럼 만들어야만 하는 줄 알았는데, 여기서는 2번처럼 만들었다. 방법이 여럿이구나.

// 1번: function으로 시작함
function emp () {
	this.name = "John";
	}
    
// 2번: 'emp는 function이다' 하는 식으로 풀어냄
var emp = function () {
	this.name = "John";
	}

 

# 다음에 할 일

 - objects, instances: 차이를 알아보기 (instances가 더 구체적이고 실질적인 대상 같은 느낌이긴 한데...)

 - Object literals, Object.create(), Constructors: 이제 Object.create()를 알아보기

 - async-await 따라해보기. (하다 말았음): https://milimiliemilie.tistory.com/11 여기의 JS Crash course 참고.