3) bind메소드로 this제어하기 this가 달라지는 경우 showHealth는 어떤 이유인지 바로 출력하지 못하고, 1초 뒤에 결과를 출력하는 함수입니다. this가 무엇을 가리킬까요? var healthObj = { name : "달리기", lastTime : "PM10:12", showHealth : function() { setTimeout(function() { console.log(this.name + "님, 오늘은 " + this.lastTime + "에 운동을 하셨네요"); }, 1000) } } healthObj.showHealth(); // 님, 오늘은 undefined에 운동을 하셨네요 위의 코드는 비동기 상황에서 일어나는 것으로, 이와 유사하게 비동기로 동작하는 이벤트 콜백에서 ..
1) 배열의 함수형 메소드 for vs forEach 아래 배열을 출력하기 위해 다음과 같이 표현이 가능합니다. var data = [{title : "hello",content : "간지철철", price : 12000}, {title : "crong",content : "괜춘한 상품", price : 5500}, {title : "codesquad",content : "쩌는상품", price : 1200}]; // for문을 이용한 방법 for(var i=0; iconsole.log(v.title,v.price)); hello 12000 crong 5500 codesquad 1200 map, filter map메서드는 함수에서 정의한 방법대로 모든 원소를 가공해서 새로운 배열을 반환합니다. 가장 중요..