JS/시나리오 코드
new 키워드와 생성자 함수
by 개발자공부
2024. 7. 19.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>index4.html 파일 입니다.</h1>
<script>
// 자바 스크립트에서 사용자 정의 객체와 생성자 함수 설계
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
// 객체 생성
const person1 = new Person("길동", "홍");
const person2 = new Person("순신", "이");
console.log(person1);
console.log(person2);
</script>
</body>
</html>