본문 바로가기

object3

[TIL] 2021-11-14 (shift, pop, Object.values, Object.entries) ▷ shift() - 배열에서 첫번째 요소를 제거(배열의 길이가 바뀜) - 제거한 값을 반환 const array1 = [1, 2, 3]; const firstElement = array1.shift(); console.log(array1); // expected output: Array [2, 3] console.log(firstElement); // expected output: 1 ▷ pop() - shift와 유사, 마지막 요소를 제거한다는 점이 다름 const plants = ['broccoli', 'cauliflower', 'cabbage', 'kale', 'tomato']; console.log(plants.pop()); // expected output: "tomato" console.lo.. 2021. 11. 14.
[JS] class와 object class와 object의 차이점 class는 붕어빵 틀, object는 붕어빵(팥 붕어빵, 슈크림 붕어빵)에 비유할 수 있다 ▷ class - class는 연관 있는 것들을 모아놓은 집합체 - template (어떤 데이터가 들어올 수 있는지 정의) - declare once (한번 선언함) - no data in ▷ object - instance of a class (class를 이용해 새롭게 생성된 instance를 object라고 함) - created many times - data in - 생성된 object는 메모리에 저장됨 객체지향 프로그래밍이란? 쉽게 말해, 자료와 함수를 함께 사용하는 것을 지향하는 프로그래밍 ▷ 출처 https://www.youtube.com/watch?v=_DLhU.. 2021. 9. 14.
[JS] object에서 method를 작성하는 두 가지 방법 method: 객체의 속성 중에 동작(함수)인 것 method를 작성하는 방법 두 가지 ▷ 첫 번째 방법 // eat() 메소드를 활용한 예시 const pet = { eat: function (food) {} } pet.eat() const superEventHandler = { handleEnter: function() { h2.innerText = "The mouse is here!"; h2.style.color = colors[0]; } } h2.addEventListener("mouseenter", superEventHandler.handleEnter); ▷ 두 번째 방법 const pet = { eat(food) } pet.eat() const superEventHandler = { handl.. 2021. 7. 31.