본문 바로가기

Development (국비 복습 )/JavaScript48

-prototype 정리 //생성자 function Person(){ this.name = "John"; this.age = 23; //prototype = ..... } //객체 만들기 const person1 = new Person(); const person2 = new Person(); //생성자에 프로퍼티 추가 Person.prototype.gender = "male"; console.log(Person.prototype); console.log(person1.gender); console.log(person2.gender); Person.face = "goodlooking"; // 이런식으로 하면 안나옴 console.log(person1.face); //유전자를 몰려주는 것을 말할 때, prototype이라고 한다 .. 2023. 3. 2.
자바스크립트 closure closure : 외부함수의 변수에 접근할 수 있는 내부함수를 일컫는다. 리턴값으로 객체를 소환하여 , 함수를 쓸 때, 외부함수를 실행하지 않고 내부함수만 실행하여, 변수의 값도 자기 자신이 가지고 있는 것을 말한다. 내부함수가 외부함수의 변수에 접근 할 수 있기 떄문에 , 함수를 소환했을 때 외부함수에 가지 않고 바로 내부함수 안에서 값을 쓸 수 있어서 시간을 절약할 수 있고, 코드도 줄일 수 있다, function outer(){ function inner(){ } } function human(){ const name = "pudding"; function sayHi(){ console.log(`hi I am ${name}`); } function howYouFeel(){ console.log(`$.. 2023. 2. 27.
구조분해할당 https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment 구조 분해 할당 - JavaScript | MDN 구조 분해 할당 구문은 배열이나 객체의 속성을 해체하여 그 값을 개별 변수에 담을 수 있게 하는 JavaScript 표현식입니다. developer.mozilla.org 다른사람 코드보다가 나왔다.. 2023. 2. 26.
재귀함수(recursive call)이란? 일단 재귀(rescursive)란 원래 자리로 되돌아가거나 되돌아 온다는 뜻이다. 따라서 자기 자신에게 되돌아 온다는 뜻을 내포하고 있다. 재귀함수의 구조 function recurse(){ //,,, recurse(); //... } 재귀함수는 반드시 함수를 멈추는 조건을 가지고 있어야한다. 그렇지 않으면 무한반복된다. function recurse(){ if(condition){ //stop calling inself }else{ recurse(); } } 간단한 재귀함수(Recursive call) 예제 3부터 1까지 카운트다운 해주는 프로그램을 만든다고 하자 3 2 1 이 countDown함수는 결과가 3만 나올 것이다. function countDown(fromNumber){ console.lo.. 2023. 2. 26.