-
Notifications
You must be signed in to change notification settings - Fork 10
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
[1주차] 송아영 미션 제출합니다. #2
Open
gustn99
wants to merge
16
commits into
CEOS-Developers:main
Choose a base branch
from
gustn99:gustn99
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
배포 링크
https://vanilla-todo-21th-4ynn0nwdc-gustns-projects.vercel.app/
production은 default 브랜치만 되는 것 같아서 preview로 배포했습니다!! 혹시 이 방식이 잘못됐다면 알려주세요!
미션을 하며 . . .
바닐라 js를 공부한 지 1년이 되었을 뿐인데 이렇게나 까마득하네요. . . 옛날 코드들도 찾아보고 즐거웠습니다 👍
지난 해 초에 혼자서 바닐라 js 공부를 할 때는
getElementById
와addEventListener
를 사용했었는데요, 그 해 3월에 시작한 스터디에서는querySelector
와 이벤트 핸들러 메서드에 할당하는 방식을 거의 강제하다시피 했었습니다. 그때는 js 공부를 시작한 것도 몇 달 안 돼서 그저 하라는 대로만 했었는데 이제서야 뭐가 뭔지 눈에도 좀 들어오고 찾아보고 비교할 여유가 생겼네요!공유하면 좋을 내용 같아 간략히 정리해 보겠습니닷
getElementById
vsquerySelector
getElementById
가 성능이 더 좋습니다. (querySelector
가 약 1.2~1.3배 느리다고 하네용)querySelector
는 다양한 css 선택자를 허용합니다..input-item input
과 같이 속성이나 자손 선택자를 사용하는 게 좋더라고요!getElementByClass
와querySelectorAll
도 유사 배열을 반환한다는 점은 같지만 실제 타입이 달라서 생기는 차이점들이 있으니 찾아보셔도 좋을 것 같습니다!이벤트 핸들러 메서드 vs
addEventListener
element.onclick() = () => {...}
와 같이 이벤트 핸들러 메서드에 직접 함수를 할당한 경우를 이벤트 핸들러 메서드라고 불러보겠습니다.addEventListener
는 중복으로 할당됩니다. 즉, 할당한 이벤트 핸들러가 모두 동작합니다.addEventListener
는 메서드에 할당하는 방식과 달리 세 번째 인자를 통해 캡처링이나 버블링 시에 동작하도록 설정할 수 있습니다.addEventListener
를 사용하는 방식으로 리팩토링했습니다! 브라우저 호환성 등 다른 차이들도 있으니 한번쯤 찾아보시면 좋겠습니다!과제 내내 리액트적 사고가 머리를 떠나지 않아서 투두 리스트를 배열로 관리하고 싶은데 엄두를 못 내겠더라고요. . . 현재 제 생각은요, 사용자 입력에 따라 배열을 업데이트하고 그 배열을 순회하며 화면을 렌더링하는 리액트와 같은 동작을 바닐라 js로는 시작도 못하고 주저하는 건, 리액트의 버추얼 돔이 바닐라에는 없다는 것을 알기 때문이 아니려나요. . . 버추얼 돔 없이 건너가기엔 너무 먼 강인 거죠. . .
비록 저는 그랬지만!! 다른 여러분들은 또 어떻게 코드를 짜셨을지 기대가 많이 됩니다!!
Key Questions
1. DOM은 무엇일까요?
mdn에서는 이렇게 정의하고 있습니다. 문서, 다르게 얘기하면 브라우저를 구성하는 노드(태그)들의 프로퍼티, 메서드, 이벤트를 객체 형식으로 담아서 프로그래밍 언어를 사용해 접근할 수 있도록 표현한 방식이다, 정도로 저는 정리해 보겠습니다.
2. 이벤트 흐름 제어(버블링 & 캡처링)이 무엇인가요?
버블링
e.stopPropagation()
을 추가하면 playing만 alert되겠죠?캡처링
3. 클로저와 스코프가 무엇인가요?
클로저
스코프
var
는 지역변수,let
과count
는 블록변수입니다. 이에 따라서 아래와 같은 흥미로운 예제가 존재하는데요,var
로 선언된 변수이기 때문에 i는 전체 함수에서 유효하고, 결국 setTimeout에서 클로저를 통해 받아오는 i의 값은 함수가 종료된 시점의 3이 됩니다.let
으로 선언하는 경우 각각의 i는 각각의 블록에서 유효하기 때문에 setTimeout에서 클로저를 통해 받아오는 i의 값도 1, 2, 3이 된다고 합니다!