[KOSTA] Spring 기반 Cloud 서비스 개발자 양성 과정 38일차 - 자바스크립트 객체 실습

JUNBEOM PARK·2022년 3월 25일
1
post-thumbnail

📃 전화번호부 생성자 함수로 구현

	function phoneInfo(name,phoneNo,birth) {
		this.name = name;
		this.phoneNo = phoneNo;
		this.birth = birth;
		this.display = function(){
			return this.name + "\t" + this.phoneNo + "\t" + this.birth
		}
	}
	
	var infos = [];
	infos.push(new phoneInfo("홍길동","111-111","010101"))
	infos.push(new phoneInfo("박길동","222-111","020202"))
	infos.push(new phoneInfo("이길동","333-333","030303"))
	infos.push(new phoneInfo("조길동","444-444","040404"))
	infos.push(new phoneInfo("황길동","555-555","050505"))
	
	document.write("===================<br>");
	document.write("phoneInfo 예제<br>");
	
	for(var i in infos){
		document.write("=====================<br>");
		document.write(infos[i].display()+"<br>");
	}



📃 Rectangle 생성자 함수를 만들고 사각형 넓이를 구하는 함수

function Rectangle(width, height){
		this.width = width;
		this.height = height;
	}
	
	Rectangle.prototype = {
			getArea : function(){
				return (this.width * this.height);
			}
	}
	
	var rectangle = new Rectangle(5, 7);
	console.log(rectangle.getArea());



📃 이전에 구현한 전화번호부 prototype으로 구현

function phoneInfo(name,phoneNo,birth){
		this.name = name;
		this.phoneNo = phoneNo;
		this.birth = birth;
	}
	
	phoneInfo.prototype = {
			display : function(){
				console.log("이름 : " + this.name + " 전화번호 : " + this.phoneNo + " 생년월일 : " + this.birth) 
			}
	}
	
	var info = new phoneInfo("홍길동", "111-111", "010101");
	
	info.display();
profile
DB 엔지니어👍

7개의 댓글

comment-user-thumbnail
2022년 3월 27일

안녕하세요! 저는 개발자를 꿈꾸고 있는 학생입니다. 현재 자바에 대한 기초 문법을 마친상태인데 저도 글쓴이님께서 진행중이신 코스타의 스프링 백엔드 과정에 관심이있는데 몇가지 여쭤봐도 될까요!!?

1개의 답글

관련 채용 정보