목차


1. javascript 사전 퀴즈

1-1. 생성자함수와 일반 함수의 this 바인딩 차이

function Cat(name, age){
	this.name = name;
	this.age = age;
}

const tabby1 = Cat('nana', 7);
console.log(tabby1.name)

<aside> 💡 생성자함수와 일반 함수의 this 바인딩 차이

</aside>

1-2. 즉시실행함수의 결과

(function(name){
	console.log(`hello ${name}`)	
}){'roto'}

즉시실행함수를 사용하는 이유

js에서 선언된 모든 변수나 함수는 전역 공간에 저장되고, 다른 파일에서 같은 변수명을 사용할 경우 오버라이딩 되는 경우가 발생한다.

1-3. functionscope와 this


var idiots = {
  name: "name",
  genre: "genre",
  members: {
    roto: {
      memberName: "roto",
      play: function () {
        console.log(this.name, this.memberName);
      },
    },
  },
};

idiots.members.roto.play(); // undefined, roto
// play내부의 this는 this를 실행시킨 객체인 roto : {memberName: - , play: f} 이기때문