목록전체 글 (102)
솔미는 성장중
colors.test() 배열 만드는 방법 1. 리터럴 방식으로 배열 만들기 const colors = ['Red', 'Green', 'Yellow', 'Blue'] 2. 생성자 함수 형식으로 배열 만들기 (new사용) const colors = new Array('Red', 'Green', 'Yellow', 'Blue') console.log(colors) //(4) ['Red', 'Green', 'Yellow', 'Blue'] //0: "Red" //1: "Green" //2: "Yellow" //3: "Blue" console.log(colors.includes('Green')) //true console.log(colors.length) //4 여기서 length, includes를 prototy..
메소드(객체 내 함수) this -> 객체 함수 this -> window object constructor function this -> 빈 객체를 가리킴 (여기다가 속성을 넣는거) 화살표 함수 this -> 상위 스코프 this 일반 함수의 this : 호출 위치에서 정의 : 아래 예제에서 this → PPAP로 바꿔주어도 결과가 동일 : 즉! this = getFullName이라는 속성이 들어있는 객체 데이터 const PPAP = { front: 'PenPineapple', end: 'ApplePen', getFullName: function() { return `${this.front} ${this.end}` } } console.log(PPAP.getFullName()) //PenPineapp..
기본 개념 setTimeout (실행할 내용, 시간) '시간' 후에 1번 실행 실행할 내용 적는 방법 () => {내용} 함수명 clearTimeout (대상) 타이머를 해제한다. setInterval (실행할 내용, 시간) '시간'마다 실행 clearInterval (대상) setInterval로 실행하던 것 해제 예제 [index.html] Click Me [main.js] const HelloWorld = () => { console.log('HelloWorld!') } const timeout = setInterval(HelloWorld,1000) const h1El = document.querySelector('h1') h1El.addEventListener('click',()=>{ consol..
하나의 함수에서 함수 자기 자신을 내부에서 다시 호출하는 것 기본적으로 무한 동작하기 때문에 필요할 때 멈춰줄 수 있게 만들어줘야 한다. 예시) 재귀 함수를 통해 최상위 포식자 찾기 const animalA = {name: 'A', predator: null} const animalB = {name: 'B', predator: animalA} const animalC = {name: 'C', predator: animalB} const getFinalPredator = animal => { if(animal.predator){ return getFinalPredator(animal.predator) } return animal.name //A } console.log(getFinalPredator(ani..
함수가 실행될 때 인수로 들어가는 함수 콜백함수는 하나의 데이터로써 사용됨 콜백은 실행위치를 보장하는 용도로 많이 사용된다! 예시 1 : b는 콜백(함수) const a = callback => { callback() console.log('A') } const b = () => { console.log('B') } a(b) //B //A 예시2 : 실행 지연 함수 & 콜백 함수 사용해보기 const sum = (a,b,c) => { setTimeout(()=> { c(a+b) }, 1000) } console.log(sum(1,2, value=>{ console.log(value) })) 해석 (흐름) setTimeout() 함수 내에서 return을 쓰더라도 그것은 setTimeout함수의 retur..