ES6 때 자바스크립트에 화살표 함수가 추가되었습니다! 기존 함수 코드 var object = { name: 'Zero', friends: ['One', 'Two', 'Three'], alertFriends: function() { var self = this; this.friends.forEach(function(friend) { alert(self.name + ' and ' + friend); }); } }; object.alertFriends(); // 세 번 알림 function(매개변수){} forEach문 안에서 this가 바뀌기 때문에 미리 self에 object의 this를 저장해서 활용했습니다. 화살표 함수 코드 const object2 = { name: 'Zero', friends: [..
ECMAScript (ES6) 화살표 함수
ES6 때 자바스크립트에 화살표 함수가 추가되었습니다! 기존 함수 코드 var object = { name: 'Zero', friends: ['One', 'Two', 'Three'], alertFriends: function() { var self = this; this.friends.forEach(function(friend) { alert(self.name + ' and ' + friend); }); } }; object.alertFriends(); // 세 번 알림 function(매개변수){} forEach문 안에서 this가 바뀌기 때문에 미리 self에 object의 this를 저장해서 활용했습니다. 화살표 함수 코드 const object2 = { name: 'Zero', friends: [..
2023.01.27